如何共享屏幕上显示的图像视图?

时间:2017-05-09 19:41:18

标签: java android share

有疑问。 如何共享屏幕上显示的图像视图?

这是一个App示例: http://www.mediafire.com/convkey/d5a3/l0b5eobtpdbeoenzg.jpg

每次在图像上点击新图像时,使用的资源就是一个在Drawable文件夹中查找ID的数组。

谢谢!!!

1 个答案:

答案 0 :(得分:1)

Try this...Don't forget to give write storage permission in manifest 
and run time for API greater than marshmallow.
Bitmap bitmap= 
BitmapFactory.decodeResource(getResources(),R.drawable.xxxx);
String path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)+"/LatestShare.jpg";
OutputStream out = null;
File file=new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path=file.getPath();
Uri bmpUri = Uri.parse("file://"+path);
 Intent shareIntent = new Intent();
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent,"Share with"));