views:

123

answers:

2

Hi, I am trying to find the sqlite database used by the MediaStore. As far as I understand, the MediaStore contains amongst others the playlists defined in the default Music app. I actually would like to duplicate a playlist, but the app does not allow that. Somehow I thought I could fix this if I just could find the actual db file. But I got completely sidetracked now, because I just cannot find the db. Btw, I am running FroYo.

+2  A: 

The proper way to do this is to use the content provider to query media store and do any kind of modifications to the tables from there.

Quick example of how you would query all artists in the MediaStore.

String[] proj = { MediaStore.Audio.Media._ID,
                        MediaStore.Audio.Media.DATA,
                        MediaStore.Audio.Media.DISPLAY_NAME,
                        MediaStore.Audio.Artists.ARTIST };
            //managed query doesn't need startManagingCursor called on the cursor
            Cursor c = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        proj, null, null, null);
smith324
Right. That's the programmatic way. I guess in this case I could just get hold of the Music player code in the first place and add a duplicate playlist function. My point, however, was that I wanted to do a quick hack, by editing the sqlite database directly using any sqlite GUI. I just wonder which file contains the db?
Hardy
Ah I see, you didn't mention you wanted to use a sqlite GUI to do this. Well as long as you have a rooted phone you should have no issues pulling the DB. I'm gonna look into its location and get back to you.
smith324
Did you find the location of the db. I really cannot find it :(
Hardy
A: 

Having a look at the Android source the class we're interested in seems to be android.provider.MediaStore and in there, the getDatabaseForUri() method seems generate a different database for each external storage card and one called internal.db.

So I think the file you're interested in is:

/data/data/com.android.providers.media/databases/internal.db

However, my copy of that database doesn't have the audio_playlists table used in the Java source so I'm not certain this is right.

Dave Webb
How do you access the data under /data. I am using ASTRO to browse the data on my phone, but /data is empty. I am not sure though whether this is because the directory is really empty or because of permission settings.
Hardy
`/data` is owned by `root` so you're not going to be able to browse it with ASTRO on an unrooted phone. Try connecting your phone to your development PC and using `adb shell`. I think this runs with root permissions on all phones but I don't have an unrooted phone with me to check this.
Dave Webb
Thanks for the info. That helps a lot and explains also why I had such a hard time finding this file. Unfortunately, 'adb shell' does not seem to run as root on an un-rooted phone :( How hard can it be!?
Hardy
@Hardy - Just had a quick Google - if you use `adb shell` and then run the `su` command you should get root access. On an unrooted phone it seems only the `root` and `shell` users can use `su` but I guess `adb shell` runs as the `shell` users so it should work.
Dave Webb
Hmm, I don't have permissions for that. Seems related to http://stackoverflow.com/questions/2078710/android-adb-access-to-application-databases-without-root
Hardy