简体   繁体   English

不支持Android Share Intent文件格式

[英]Android Share Intent file format not supported

I am trying to share an image from my drawable folder. 我想从我的drawable文件夹中共享一个图像。 It worked before but now for some reason whenever I try to share I will select the person to share it to, and it will give me an message that says: "file format is not supported". 它以前工作但现在由于某种原因,每当我尝试分享时,我会选择分享给它的人,它会给我一条消息:“不支持文件格式”。 For some reason I can't share it with Whatsapp, but I can share it with another app like snapchat. 出于某种原因,我无法与Whatsapp分享,但我可以与像Snapchat这样的其他应用分享。 So I know it is getting the correct image. 所以我知道它正在获得正确的图像。

Here is my sharing code: 这是我的共享代码:

Uri imageUri;
imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "image" + String.valueOf(mViewPager.getCurrentItem() + 1));
//imageUri = Uri.parse("android.resource://" + getPackageName() + R.drawable.image1);
Log.d("Sharing", "android.resource://" + getPackageName() + "/drawable/" + "image" + String.valueOf(mViewPager.getCurrentItem() + 1));
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
//sharingIntent.putExtra(Intent.EXTRA_TEXT, "Ha Ha! Check out this picure I got with todays date! Download the app: http://www.google.com");
sharingIntent.setType("image/jpg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sharingIntent, "Share via"));

Here is an error I got from the logs, but I am not using an ArrayList to share. 这是我从日志中得到的错误,但我没有使用ArrayList来共享。

W/Bundle: Key android.intent.extra.STREAM expected ArrayList but value was a android.net.Uri$StringUri.  The default value <null> was returned.

And what the Log.d prints out: 以及Log.d打印出的内容:

D/Sharing: android.resource://com.trommelen.okke.scheurkalender/drawable/image155

I have solved this problem by adding a bitmap and add the permission android.permission.WRITE_EXTERNAL_STORAGE to the Manifest 我通过添加位图并将权限android.permission.WRITE_EXTERNAL_STORAGE添加到清单来解决了这个问题

Bitmap imgBitmap=BitmapFactory.decodeResources(getResources(),R.drawable.image1);
String imgBitmapPath=Images.Media.insertImage(getContentResolver(),imgBitmap,"title",null);
Uri imgBitmapUri=Uri.parse(imgBitmapPath);

then add the imgBitmapUri as extra stream. 然后将imgBitmapUri添加为额外的流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM