Android分享图片意图:WhatsApp - 不支持文件格式

时间:2016-06-15 10:56:21

标签: android image android-intent share whatsapp

我在将应用程序中的图像分享到WhatsApp时遇到了问题。

int imageId = getResources().getIdentifier("image_name", "drawable", getPackageName());

Uri imageUri = Uri.parse("android.resource://com.companyname.packagename/drawable/"+ imageId);

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");                       
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));

此代码适用于Facebook Messenger或Androids内置信使。 但它不适用于WhatsApp。我收到此错误消息:

“不支持文件格式!”

  

我使用@CommonsWare解决方案解决了这个问题:   https://github.com/commonsguy/cwac-provider

4 个答案:

答案 0 :(得分:0)

shareIntent.setType("image/jpeg"); 

REPLACE BY shareIntent.setType("image/*"); //it support all type of files.

答案 1 :(得分:0)

`Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);     shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);     shareIntent.setType("图像/ *&#34);

//set your message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msgText); 

String imagePath = Environment.getExternalStorageDirectory() + File.separator + "image_name.jpg";

File imageFileToShare = new File(imagePath);

Uri uri = Uri.fromFile(imageFileToShare);

shareIntent.putExtra(Intent.EXTRA_STREAM, uri);`

答案 2 :(得分:0)

替换shareIntent.setType("image/jpeg");

有了这个 shareIntent.setType("image/*");,这将选择所有类型的图像,也许这对你有用,因为它对我来说很好。

答案 3 :(得分:-1)

mIntent.setType("image/png");

替换它。它可能有用。

相关问题