通过意图共享图像失败

Sharing image failed via intents

我正在尝试使用 intents 分享图像。请找到相同的函数。

        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 文件夹中,也尝试更改位置但没有 use.Could 有人帮忙吗?谢谢!

EXTRA_STREAMdocumented 采取 Uricontent: 方案。 android.resource: 不是 content:。当他们从您的应用程序收到它时,没有任何应用程序知道如何处理您的 Uri 的要求。另外,您的 Uri 以 semi-random 数字结尾(无论 R.mipmap.test 恰好用于此版本)。

请将图像复制到文件中(例如,在 getCacheDir() 中),然后使用 FileProvidergetUriForFile() 获取 Uri 以用于 [=10] =].