Solution 1 :
Even though MediaStore.VOLUME_EXTERNAL
was added in API 29, but you are safe to use it as long as you set targetSdkVersion
and compileSdkVersion
to 29+. I have tested it on API 16 and this constant did not crash my app.
However, if you think this warning is pretty annoying, you can use MediaStore.<MediaType>.EXTERNAL_CONTENT_URI
instead. It will return the same value as MediaStore.<MediaType>.getContentUri(MediaStore.VOLUME_EXTERNAL)
.
For instance, MediaStore.Downloads.EXTERNAL_CONTENT_URI
will equal to MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL)
, i.e. content://media/external/downloads
.
Additionally, you can ignore this warning via @SuppressLint("InlinedApi")
.
Problem :
In Android documentation they said
On API <= 28, use VOLUME_EXTERNAL
but this also requires API level 29, and it doesn’t save media files into MediaStore.
MediaStore.Audio.Media.IS_PENDING
MediaStore.Video.Media.RELATIVE_PATH
MediaStore.Video.Media.DATE_TAKEN
also requires API 29, So I feel the doc is not clear, or is there anything I missed?. And how do I save the media files in below Android 10 as well.
Comments
Comment posted by AndroidRuntimeException
I am blocked in the same part. I am trying to take a photo or select one from the gallery and set as profile but for some reason I am not able to figure out how works this. If you put val collection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) } else { MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL) } returns the same warning
Comment posted by Guilherme Santos
do you know if this is also true for the DATE_TAKEN and RELATIVE_PATH MediaColumns?
Comment posted by Akshay Kalola
MediaStore.<MediaType>.EXTERNAL_CONTENT_URI
Comment posted by Waqas Younis
Hey @AkshayKalola, you manage to find and solution for files?