0
private void createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    String file = "/mnt/sdcard/9gag_4155804.jpg";
    File f = new File(file);
    if (!f.exists()) {
        Toast.makeText(getApplicationContext(), "File doesnt exists", Toast.LENGTH_SHORT).show();
        return;
    } else {
        Toast.makeText(getApplicationContext(), "We can go on!!!", Toast.LENGTH_SHORT).show();
    }
    Uri uri = Uri.fromFile(f);
    shareIntent.setType("image/jpeg");
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(shareIntent, "How do you want to share?"));
}  

该文件存在,我没有收到 Toast。调用此方法时,许多意图都是列表。(Google Drive、Mail、Plus 等)我点击 Google Plus,它告诉我“并非所有媒体文件都可以附加到帖子中”。使用 Google Drive 或任何其他服务时也会发生同样的情况。我只是无法分享任何图像...

有任何想法吗?

// 编辑我得到 Toast "We can go on!!!"

4

1 回答 1

-3

您是否在清单中定义了意图过滤器。如果不添加这个:

 <intent-filter>
            <action android:name="android.intent.action.SEND" />

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

您需要通知 android 系统这是一个隐式意图。

于 2012-06-25T10:17:33.907 回答