0

我正在向 facebook、twitter、Linkedin、picasa 分享一张照片。我可以毫无问题地分享文本。任何人都可以用一些例子来解释如何分享一张照片。目前我正在使用以下代码(添加一个简单的分享操作)

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);
    }
  }
}

提前致谢

4

3 回答 3

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"));

注册意图

如果您希望在调用此 Intent 时列出您的应用,则必须在 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、twitter、Linkedin 等上选择 facebook 和共享照片。

于 2013-11-21T11:10:39.493 回答
0

试试这个代码:

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

它将打开选择器对话框,其中包含允许照片共享功能的所有可能应用程序。只需选择 Facebook、Twitter 或您要在其上共享照片的任何其他应用程序。

于 2013-11-21T10:25:56.870 回答
0

SocialLib是一个优秀的安卓共享工具包(iOS 最好的是ShareKit)。

SocialLib 允许集成:Facebook Twitter Google Buzz LinkedIn

如果您只想使用 facebook 分享,请关注Facebook Share Dialog

于 2013-11-21T10:31:24.733 回答