Due to Scoped Storage, we can’t write the image directly to shared storage locations via direct file path. This approach is deprecated in android Q and will be enforced to stop using in 2020.
Storing shared media files. For apps that handle files that users expect to be sharable with other apps (such as photos) and be retained after the app has been uninstalled, use the MediaStore API. There are specific collections for common media files: Audio, Video, and Images. For other file types, you can store them in the new Downloads collection. To access files from the Downloads collection, apps must use the system picker.
Storing app-internal files. If your app is designed to handle files not meant to be shared with other apps, store them in your package-specific directories. This helps keep files organized and limit file clutter as the OS will manage cleanup when the app is uninstalled. Calls to Context.getExternalFilesDir() will continue to work.
We can still use saveToFile, making sure the constructed file path is within the scoped storage of the app. As stated before, we just have to make sure we use Context.getExternalFilesDir() to save in scoped storage.
However, there's no way to save in the shared media collection locations, since that has to be done via the usage of MediaStore.
Possible solution
As an alternative to the existing PhotoResult#saveToFile, a new PhotoResult#saveToImagesMediaStore (open to other names / function signatures) could be exposed.
TODO
Write rotation Exif metadata (the current ExifWriter uses a file as input)
Problem
Due to Scoped Storage, we can’t write the image directly to shared storage locations via direct file path. This approach is deprecated in android Q and will be enforced to stop using in 2020.
From Google's Scoped Storage best practices:
We can still use
saveToFile
, making sure the constructed file path is within the scoped storage of the app. As stated before, we just have to make sure we useContext.getExternalFilesDir()
to save in scoped storage.However, there's no way to save in the shared media collection locations, since that has to be done via the usage of
MediaStore
.Possible solution
As an alternative to the existing
PhotoResult#saveToFile
, a newPhotoResult#saveToImagesMediaStore
(open to other names / function signatures) could be exposed.TODO