int checkExistence = getResources().getIdentifier("image_"+position, "drawable", getPackageName());
Bitmap bitmapToShare = BitmapFactory.decodeResource(
getResources(), checkExistence);
File pictureStorage = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File noMedia = new File(pictureStorage, ".nomedia");
if (!noMedia.exists())
noMedia.mkdirs();
File file = new File(noMedia, "meme_shared_image.png");
if (saveBitmapAsFile(bitmapToShare, file)) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(shareIntent, "Share image using"));
}
else
{
Toast.makeText(MainActivity.this, "Sending Error", Toast.LENGTH_LONG).show();
}
}
private boolean saveBitmapAsFile(Bitmap bitmapToShare, File file) {
FileOutputStream out;
try {
out = new FileOutputStream(file);
bitmapToShare.compress(Bitmap.CompressFormat.JPEG, 90, out);
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
}
已修复..希望这在某个时候对其他人有所帮助。如何通过 viber 和 google hangout 共享可绘制图像?这给了我帮助