0

I am trying to find out whether I have to save image to external storage and then to Gallery, thus needing WRITE_EXTERNAL_STORAGE, or I can do with Fileprovider.

Is something like this possible?

    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);

How do I grant READ_URI_PERMISSION to Gallery (Mediastore)?

Martin D
  • 1
  • 1

1 Answers1

0

See https://stackoverflow.com/a/44455957/966789 (Android added new permission model for Android 6.0 Marshmallow).

... and handle the result in 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();
            }
Alexander Lubyagin
  • 1,346
  • 1
  • 16
  • 30