我正在尝试从我的drawable文件夹中共享图像。它之前有用但现在出于某种原因,每当我尝试分享时,我都会选择分享给它的人,它会给我一条消息:"文件格式不受支持"。出于某种原因,我无法与Whatsapp分享,但我可以与像Snapchat这样的其他应用分享。所以我知道这是正确的形象。
这是我的分享代码:
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"));
这是我从日志中得到的错误,但我没有使用ArrayList来共享。
W/Bundle: Key android.intent.extra.STREAM expected ArrayList but value was a android.net.Uri$StringUri. The default value <null> was returned.
Log.d打印出来的内容:
D/Sharing: android.resource://com.trommelen.okke.scheurkalender/drawable/image155
答案 0 :(得分:1)
我通过添加位图并将权限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);
然后将imgBitmapUri
添加为额外的流。