Android 如何通过viber和google hangout共享可绘制图像?
当我通过whatsapp共享图像时,我的代码运行良好……但对于viber,google hangout im出现“找不到照片”错误。 这是我的代码:Android 如何通过viber和google hangout共享可绘制图像?,android,hangout,viber,Android,Hangout,Viber,当我通过whatsapp共享图像时,我的代码运行良好……但对于viber,google hangout im出现“找不到照片”错误。 这是我的代码: int ImageResourse=imageAdapter.mThumbIds[position]; Uri path = Uri.parse("android.resource://dragonflymobile.stickers.lifestickers/" + ImageResour
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
很少有应用程序支持
android.resource
方案
欢迎您使用
内容
方案共享内容,例如通过文件提供商
,因为更多的应用程序将支持这一点。我找到了一个解决方案,无需使用文件提供商或安卓资源方案。thnx Commonware用于解释android.resource方案的情况
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();
}