问题
my code works fine when i share a image via whatsapp....but for viber , google hangout im getting "can't find photo" error. this is my code :
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
回答1:
i found a solution to this without using FileProvider or android.resource scheme . thnx CommonsWare for explaining the situation with 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();
}
回答2:
Few, if any, apps support the android.resource
scheme.
You are welcome to share things using the content
scheme, such as via FileProvider
, as more apps will support that.
来源:https://stackoverflow.com/questions/25334647/how-to-share-drawable-image-via-viber-and-google-hangout