内部ストレージに保存されたスクリーンショットを共有したいが、共有中はブランク画面が表示されます。私は、別のアプリがプライベートデータを取得したアプリを使用できないことを知りました。内部ストレージのスクリーンショットを共有します。android
File path = new File(getApplicationContext().getDir("Default", Context.MODE_ENABLE_WRITE_AHEAD_LOGGING),"myapp");
File directory = new File(path.getAbsolutePath());
directory.mkdirs();
String filename = "myapp.png";
File yourFile = new File(directory, filename);
try
{
FileOutputStream out = new FileOutputStream(yourFile, true);
bitmap.compress(Bitmap.CompressFormat.PNG, 90,out);
out.flush();
out.close();
send(yourFile);
}catch (IOException e)
{
e.printStackTrace();
}
して共有意図されています:これは私がイメージを保存するために使用したコードである
public void send(File path)
{
Uri uri = Uri.fromFile(path);
Log.d("uri", String.valueOf(path));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "My App");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share via"));
}
画像が保存されてきているとパスの値がであるパス:
/data/user/0/com.sample.myapp/app_Default/myapp/myapp.png
スクリーンショットにアクセスして共有できるようにする方法を確認するにはどうすればいいですか?
私はコードを実装しており、上記のコードを編集しました。今私がコードを実行すると、アプリケーションがクラッシュしています。どこが間違っていますか? –
例外は何ですか? – Sach
これは私が得ているものです "java.lang.NullPointerException:ヌルオブジェクト参照でインタフェースメソッド 'boolean android.database.Cursor.moveToFirst()'を呼び出そうとしました" –