esafirm / android-image-picker

Image Picker for Android 🤖
MIT License
1.11k stars 327 forks source link

Android 10: write to shared storage #287

Open cschulteksa opened 4 years ago

cschulteksa commented 4 years ago

Consider adding an option to write to shared storage on Android 10 using a method similar to this:

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, timeStamp + ".jpg");
    fileUri = getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    ParcelFileDescriptor descriptor = getActivity().getContentResolver().openFileDescriptor(fileUri, "w");
    FileOutputStream os = new FileOutputStream(descriptor.getFileDescriptor());
    IOUtils.write(bytes, os);

Code is a little rough, but this works even with requestLegacyExternalStorage turned off on Android 10.

esafirm commented 1 year ago

Wondering is this related to https://github.com/esafirm/android-image-picker/issues/380