我正在尝试使用意图共享图像。请找到相同的功能。
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">
我无法理解。我尝试将manifest标签更改为drawable,并因此将imag保留在drawable中,并进行相应的更改仍然没有运气。我将图像保存在项目的mipmap-anydpi-v26文件夹中,还尝试更改位置但没有用。有人可以帮忙吗?谢谢!
答案 0 :(得分:1)
EXTRA_STREAM
是documented,采用Uri
方案的content:
。 android.resource:
不是content:
。无需任何应用从他们的应用收到您的Uri
时就知道如何处理它们。另外,您的Uri
以半随机数结尾(无论R.mipmap.test
恰好适用于此版本)。
请将该图像复制到文件中(例如,在getCacheDir()
中),然后使用FileProvider
和getUriForFile()
获得Uri
用于EXTRA_STREAM