私は、ACTION_SENDを使用してアプリの現在のビューを共有したいと考えています。アンドロイドに画像を保存せずに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上で(アクセス権なし)の外部記憶装置に格納することなく同じことを実行する方法はありますか?
他の方法(view-> bitmap-> storage/contentprovider以外)は、アプリケーションの現在のビューを変換し、他のアプリと共有する方法はありますか? – Rishi
@Rishi:そうではありません。スクリーンショットの部分にAndroid 5.0以降のメディアプロジェクションAPIを使用できます。 – CommonsWare
あなたのすべての質問にお返事いただきありがとうございます。 fileProviderを使用してメモリ内の画像を共有する際の問題に直面しています。 http://stackoverflow.com/questions/41615290/sharing-bitmap-in-memory-without-asking-for-read-permissions-using-action-send – Rishi