【发布时间】:2012-06-25 10:07:27
【问题描述】:
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。 调用此方法时,许多意图都是列表。 (谷歌云端硬盘、邮件、Plus 等) 我点击 Google Plus,它告诉我“并非所有媒体文件都可以附加到帖子中”。 使用 Google Drive 或任何其他服务时也会发生同样的情况。 我就是不能分享任何图片...
有什么想法吗?
// 编辑 我得到祝酒词“我们可以继续!!!”
【问题讨论】:
-
尝试将 Toast 放入
else并检查... -
添加了,我得到了“我们可以继续”的祝酒词
-
使用
Environment.getExternalStorageDirectory()并检查您提供路径的文件夹中有图像 -
是的,图像在那里。其他应用程序也可以访问它...
-
尝试使用 mnt/sdcard/9gag_4155804.jpg 代替 /mnt/sdcard/9gag_4155804.jpg
标签: android android-intent share