【问题标题】:Share Intent doesnt work for image?共享意图不适用于图像?
【发布时间】: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


【解决方案1】:

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

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

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

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

【讨论】:

  • Intent Filter 用来告诉Android系统我的应用可以接收共享图片,或者?
  • 是的,您需要在清单中声明这一点,以便 android 系统在列表中列出您的应用。当您点击分享按钮时
  • 我不想接收分享。我想将一些图像分享给其他应用程序
猜你喜欢
  • 1970-01-01
  • 2015-09-21
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-03
相关资源
最近更新 更多