ドローアブル フォルダーに大量の写真を保存するアプリを作成します。ユーザーが写真を長押しすると、メニューが表示されます。オプションの 1 つは共有です。コンテキスト メニューを表示できますが、共有方法がわかりません。グリッドメニューから。
また、独自のビューで単一の画像を表示し、そこから共有できる拡張機能もあります。
しかし、ユーザーがグリッドビューから画像を選択すると、その画像を共有する方法がわかりません。
これは、ユーザーが共有オプションを選択したときに呼び出すメソッドです
public Intent intentShare() {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://your.package.here/drawable/"+share.putExtra("id", lastPosition)));
startActivity(Intent.createChooser(share, "Share Image"));
return share;
}
他のいくつかの質問で、この可能なオプション/解決策を見てきました
Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));
しかし、それが機能する場合、mBitmap を初期化する方法がわかりません。
コード全体はここにあります: http://pastie.org/private/gdpyn2t55h0gp1vp1kika