Using MediaStore

One of the Google-recommended alternatives to working directly with external storage is to use MediaStore. MediaStore, unfortunately, has never had particularly good documentation. And, some aspects of using MediaStore changed in Android 10.

For general-purpose apps, the Storage Access Framework is a better solution for storing content. However, if your app has a particular focus on audio, video, or image media, then MediaStore is well worth consideration.

What Not To Do

Due to the shortage of documentation, proper use of MediaStore has always been a mess, rife with anti-patterns.

The biggest anti-pattern involves the use of the DATA column. Too many developers try using query() on a ContentResolver, given a MediaStore Uri, to get the DATA column. Those developers then treat the result as a filesystem path to access the media.

However:

And, on Android 10, the MediaStore specifically will redact the DATA column from any query results.

To get a Uri that you can use with ContentResolver for things like openInputStream():


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.