2017-03-31 21 views
0

画像を外部ストレージに保存してからギャラリーに保存する必要があるかどうかを調べるため、WRITE_EXTERNAL_STORAGEが必要ですか、Fileproviderを使用できます。fileproviderを使用して画像をギャラリーに保存

これは可能でしょうか?

Uri uri = FileProvider.getUriForFile(getApplicationContext(), Config.CAPTURE_IMAGE_FILE_PROVIDER, imageFile); 
    ContentValues values = new ContentValues();  
    values.put(MediaStore.Images.Media.DATA, uri.toString()); 
    ... 
    ContentResolver cr = getContentResolver(); 
    Uri mediaStoreUri = cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 

Gallery(Mediastore)にREAD_URI_PERMISSIONを許可するにはどうすればよいですか?

答えて

0

https://stackoverflow.com/a/44455957/966789(Android 6.0 Marshmallowの新しい許可モデルがAndroidに追加されました)を参照してください。

...とonRequestPermissionsResult(に結果を扱う):

  File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
      File file = new File(path, "sample.JPG"); 
      try { 
       file.createNewFile(); 
      } 
      catch (IOException e) { 
       Toast.makeText(this.getApplicationContext(),"createNewFile:"+e.toString(),Toast.LENGTH_LONG).show(); 
      } 
関連する問題