2013-11-21 18 views
0

我正在與facebook,twitter,Linkedin,picasa共享一張照片。我可以分享文本沒有任何problem.Can任何一個有一些例子來說明如何共享一個photo.For的那一刻,我用下面的代碼(添加一個便於分享行動)如何在android中共享一張照片?

private ShareActionProvider mShareActionProvider; 

    public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate menu resource file. 
    getMenuInflater().inflate(R.menu.main, menu); 
    MenuItem item = menu.findItem(R.id.menu_item_share); 
    mShareActionProvider = (ShareActionProvider) item.getActionProvider(); 
    Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
    //Uri screenshotUri = Uri.fromFile(new File(getFilesDir(), ".jpg")); 
    Log.d("Storage dir ", "Getting the directory"); 
    File f = FileUtils.getStorageDir(); 
    Log.d("All Answers: ", f.getAbsolutePath()); 
    sharingIntent.setType("image/png"); 
    sharingIntent.putExtra(Intent.EXTRA_STREAM,f);  
    startActivity(Intent.createChooser(sharingIntent, "Share image using")); 
    // Set the share Intent 
    mShareActionProvider.setShareIntent(sharingIntent); 
    return true; 
    } 

    // Call to update the share intent 
    private void setShareIntent(Intent shareIntent) { 
    if (mShareActionProvider != null) { 
     mShareActionProvider.setShareIntent(shareIntent); 
    } 
    } 
} 

在此先感謝

+0

我回答了這樣的問題: http://stackoverflow.com/questions/19700889/share-link-via-intent-from-preferencescreen/19704522#19704522 – user2940520

回答

0

試試這個代碼:

Intent share = new Intent(Intent.ACTION_SEND); 
    share.setType("image/*"); 
    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath))); 

這將打開選擇對話框與所有可能的應用使照片共享facility.Just選擇Facebook,Twitter或您要分享您的照片任何其他應用程序。

0

SocialLib是一個優秀的Android的共享套件(對於iOS最好的是ShareKit)。

SocialLib允許整合: Facebook的Twitter的 谷歌 巴茲 LinkedIn

如果你希望只使用Facebook的共享遵循Facebook Share Dialog

1

共享二進制對象(圖片,視頻等) 您可以使用此代碼

除了支持文字,這個意圖也支持共享圖像或任何二進制內容。您所要做的就是設置合適的MIME類型,然後通過調用put Extra方法來傳遞二進制數據。

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
Uri screenshotUri = Uri.parse(path); 

sharingIntent.setType("image/png"); 
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); 
startActivity(Intent.createChooser(sharingIntent, "Share image using")); 

註冊的意圖

如果想上市的應用程序時,這個意圖是所謂的,那麼你必須在你的manifest.xml文件添加一個意圖過濾

<intent-filter> 
    <action android:name="android.intent.action.SEND" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="image/*" /> 
</intent-filter> 

你會打開選擇器對話框,並選擇Facebook和臉譜,微博,Linkedin等共享照片。

相關問題