2013-02-05 100 views
0

我想在我的應用中分享多張照片。我可以使用臉譜圖API上傳一張照片,但我怎樣才能分享多張照片在臉書上分享多張照片

Thanx。

+0

的可能重複的[意圖+分享+行動\ _Send \ _Multiple + Facebook的不工作(http://stackoverflow.com/questions/25846496/intent-share-action-send-多Facebook的 - 不工作) – bummi

回答

1

Android不提供外的現成意圖用於選擇多個圖像/圖片,或任何其他媒體類型。資料來源:https://stackoverflow.com/a/12919585/450534(我通常會把馬克墨菲的話當作福音,除非有人可以挑戰它)

最接近的意圖是ACTION_SEND_MULTIPLE.那。但是,不適合你。

您將需要創建一個自定義選擇器類似於Facebook自己的移動應用程序。

你會得到一個完整的運行例子在這裏實現自己的多重圖像選擇:http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/

最後,在一氣呵成多個圖像上傳到Facebook,你將需要發送Batch Requests

但是,當然沒有現成的解決方案,您正在尋找的東西。結合上述所有內容,然後你就可以。但恐怕沒有什麼直截了當的。

0

我設法使用意圖在Facebook上分享多張照片。 變量「caminhos」是一個ArrayList < String>,其中包含要共享的圖像的路徑。

protected void share(String nameApp, String imagePath, String text) { 
// TODO Auto-generated method stub 

try { 
    List<Intent> targetedShareIntents = new ArrayList<Intent>(); 
    Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
    share.setType("image/jpeg"); 
    List<ResolveInfo> resInfo = getActivity().getPackageManager() 
      .queryIntentActivities(share, 0); 
    if (!resInfo.isEmpty()) { 
     for (ResolveInfo info : resInfo) { 
      Intent targetedShare = new Intent(
        android.content.Intent.ACTION_SEND_MULTIPLE); 
      targetedShare.setType("image/png"); // put here your mime 
      // type 
      if (info.activityInfo.packageName.toLowerCase().contains(
        nameApp) 
        || info.activityInfo.name.toLowerCase().contains(
          nameApp)) { 
       targetedShare.putExtra(Intent.EXTRA_SUBJECT, text); 
       targetedShare.putExtra(Intent.EXTRA_TEXT, text); 
       ArrayList<Uri> files = new ArrayList<Uri>(); 
       for(int j= 0;j<caminhos.size();j++){ 
        if(!caminhos.get(j).isEmpty()){ 
         File file = new File(caminhos.get(j)); 
         Uri uri = Uri.fromFile(file); 
         files.add(uri); 
        } 
       } 

       targetedShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM, 
         files); 
       targetedShare.setPackage(info.activityInfo.packageName); 
       targetedShareIntents.add(targetedShare); 
      } 
     } 
     Intent chooserIntent = Intent.createChooser(
       targetedShareIntents.remove(0), "Select app to share"); 
     chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, 
       targetedShareIntents.toArray(new Parcelable[] {})); 
     startActivity(chooserIntent); 
    } 
} catch (Exception e) { 
} 

}