当我通过whatsapp共享图像时,我的代码工作正常....但对于viber,谷歌视频群聊即时“无法找到照片”错误。 这是我的代码:
int ImageResourse=imageAdapter.mThumbIds[position];
Uri path = Uri.parse("android.resource://dragonflymobile.stickers.lifestickers/" + ImageResourse);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, path);
((Activity)getActivity()).setResult(Activity.RESULT_OK, shareIntent); //set the file/intent as result
((Activity)getActivity()).finish(); //close your application and get back to the requesting application like GMail and WhatsApp
答案 0 :(得分:1)
我在不使用FileProvider或android.resource方案的情况下找到了解决方案。 thnx CommonsWare用于解释android.resource scheme的情况
int ImageResourse = imageAdapter.mThumbIds[position];
Bitmap bitmapToShare = BitmapFactory.decodeResource(
getResources(), ImageResourse);
File pictureStorage = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File noMedia = new File(pictureStorage, ".nomedia");
if (!noMedia.exists())
noMedia.mkdirs();
File file = new File(noMedia, "shared_image.png");
if (GeneralFunctions.saveBitmapAsFile(bitmapToShare, file)) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
((Activity) getActivity()).setResult(Activity.RESULT_OK, shareIntent);
((Activity) getActivity()).finish();
}
else
{
Toast.makeText(getActivity(), "Sending Error", Toast.LENGTH_LONG).show();
}
答案 1 :(得分:0)
很少(如果有的话)应用支持android.resource
计划。
欢迎您使用content
计划分享内容,例如通过FileProvider
,因为更多应用会支持此功能。