VOLUME_EXTERNAL require API level 29

Viewed 1825

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.

1 Answers

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").

Related