简体   繁体   中英

Is it possible to do a raw query on Android's media meta sqlite database?

I'm writing a small app to play music. My target is Android API level 7 and up.

The app should only list and play music that has been tagged with a specific set of genres chosen by the user via the preferences, eg "Pop", "Rock", "Hillbilly".

Right now I'm trying to find an efficient way to find all album ids and album names that contain tracks which are tagged with the chosen genres.

This is easy in SQL. The phone stores the media meta data in an sqlite database. I have found it on the phone's internal memory, copied it via adb and tried some sqlite queries on it. The resulting query is an SQL one-liner with a chain of joins and it works fine.

This seems to be more difficult in Java with the Android SDK, at least with API level 7 and up. I can use managedQuery on the MediaStore to do some limited SQL syntax on that same underlying database, but if I understand things correctly there is no JOIN and no DISTINCT when using this API.

Also I may have overlooked this, but MediaStore allows me to search for all tracks of one genre, but not for all tracks of several genres in a single query.

So this all gets a bit of manual work in java. The program now has to do several managedQuery() calls for each genre and the program has to join the results and make them distinct with java, outside of sqlite (where this work belongs).

Is this really how it has to be done? Is there no way to just send a raw query to the sqlite database file?

Thanks!

No you can not directly access the underlying structure of the database -- in fact you have no way to know the actual structure of the database, it has changed across platform versions. The only direct queries you can do are the ones provided through the MediaStore protocol of the content provider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM