【问题标题】:Sharing image failed via intents通过意图共享图像失败
【发布时间】:2020-10-18 13:59:07
【问题描述】:

我正在尝试使用意图共享图像。请找到相同的功能。

        if(view.getId()==R.id.sendImage){
        Uri imgUri=Uri.parse("android.resource://com.example.watchyalist/mipmap/"+R.mipmap.test);
        intent=new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_STREAM,imgUri);
        intent.putExtra(intent.EXTRA_TEXT,"Please find the image");
        chooser=Intent.createChooser(intent,"Choose the app");
        startActivity(chooser);
    }

这里的测试是我指的图像,它通过whatsapp共享时发送bin文件。我尝试使用 ic_launcher,然后它说共享失败。这是我的清单文件的快照

 android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

我无法理解。我尝试将清单标签更改为可绘制并因此将图像保持为可绘制并相应地进行更改仍然没有运气。我已将图像保存在项目的 mipmap-anydpi-v26 文件夹中,并且还尝试更改位置但没有用。有人可以帮忙吗?谢谢!

【问题讨论】:

    标签: android image android-intent


    【解决方案1】:

    EXTRA_STREAM 是 documented 以采用 Uri 和 content: 方案。 android.resource: 不是 content:。当任何应用程序从您的应用程序收到Uri 时,他们不需要知道如何处理您的Uri。另外,您的 Uri 以半随机数字结尾(无论 R.mipmap.test 恰好是这个版本)。

    请将图像复制到文件中(例如,在getCacheDir() 中),然后使用FileProvider 和getUriForFile() 获取Uri 以用于EXTRA_STREAM。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2012-05-05
      • 2017-07-01
      相关资源
      最近更新 更多