2016-06-30 21 views
0

内部ストレージに保存されたスクリーンショットを共有したいが、共有中はブランク画面が表示されます。私は、別のアプリがプライベートデータを取得したアプリを使用できないことを知りました。内部ストレージのスクリーンショットを共有します。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

スクリーンショットにアクセスして共有できるようにする方法を確認するにはどうすればいいですか?

答えて

0

この画像のURIを渡してもらう

は実際のパスはこの

public String getRealPathFromURI(Uri uri) { 
    Cursor cursor = getContentResolver().query(uri, null, null, null, null); 
    cursor.moveToFirst(); 
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
    return cursor.getString(idx); 
} 

をチェック取得する画像URIない実像パスを取得していますイメージを外部ストレージに転送して共有します。

String url = null; 
    try { 
     url = MediaStore.Images.Media.insertImage(getContentResolver(), path.getAbsolutePath(), path.getName(), path.getName()); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 
    Uri uri = Uri.parse(url); 
0

あなたはちょうど私がエクスポートして、それを解決し、完全な画像のパスに

+0

私はコードを実装しており、上記のコードを編集しました。今私がコードを実行すると、アプリケーションがクラッシュしています。どこが間違っていますか? –

+0

例外は何ですか? – Sach

+0

これは私が得ているものです "java.lang.NullPointerException:ヌルオブジェクト参照でインタフェースメソッド 'boolean android.database.Cursor.moveToFirst()'を呼び出そうとしました" –

関連する問題