【发布时间】:2017-01-05 20:10:24
【问题描述】:
我想使用 ACTION_SEND 分享应用的当前视图。
将当前视图转换为位图并将其存储在外部存储中以将位图转换为可解析Uri的方法需要权限。
片段:
public static Bitmap getScreenShot(View view) {
View screenView = view.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
return bitmap;
}
// View to BitMap
Bitmap b = getScreenShot(getWindow().getDecorView().findViewById(android.R.id.content));
//BitMap to Parsable Uri (needs write permissions)
String pathofBmp = MediaStore.Images.Media.insertImage(getContentResolver(), b,"title", null);
Uri bmpUri = Uri.parse(pathofBmp);
//Share the image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
这需要 WRITE_EXTERNAL_STORAGE 权限, 有没有办法在不将其存储在 Android 上的外部存储(无权限)的情况下执行相同的操作?
【问题讨论】:
标签: java android share android-permissions android-sharing