Connect to the Droid's Database?


Last Updated:

  1. Merlin2000

    Merlin2000 Active Member This Topic's Starter

    Joined:
    Nov 25, 2009
    Messages:
    31
    Likes Received:
    0
    How do I access an application's database? I've done some basic Android programming before, but never actually grabbed an existing database from a phone (in this case, the Droid). I'm very familiar with sqlite, just don't know where to get the database!
     

    Advertisement
  2. Loki117

    Loki117 Guest

    Can you explain some more what you are trying to do Merlin? You probably don't have access to another applications DB but there may be a way around this if you are trying to gain access to contacts or something?

    Tom

     
  3. Merlin2000

    Merlin2000 Active Member This Topic's Starter

    Joined:
    Nov 25, 2009
    Messages:
    31
    Likes Received:
    0
    I'm not sure what the options are with the Droid. I wanted to access the installed application's databases, not just the contacts.

    Is there a list of all the databases somewhere accessible? If I install an app, there has to be a way to view the database info... Is this something I would need root access for?
     
  4. Loki117

    Loki117 Guest

    Hey Merlin try something like this to get all installed apps.

    ArrayList<String> installedApps = new ArrayList<String>();

    PackageManager applicationName = getPackageManager();
    List<ApplicationInfo> applist = applicationName.getInstalledApplications(0);
    Collections.sort(applist , new ApplicationInfo.DisplayNameComparator(applicationName));


    for (int index=0; index< applist.size(); index++) {
    ApplicationInfo info = applist.get(index);
    getPackageManager().getApplicationLabel(info);
    installedApps.add((String) getPackageManager().getApplicationLabel(info));
    }
     
  5. Merlin2000

    Merlin2000 Active Member This Topic's Starter

    Joined:
    Nov 25, 2009
    Messages:
    31
    Likes Received:
    0
    I'm actually trying to get the databases, not the list of installed applications.

    I want to view/edit/modify a database on the phone.
     
  6. Loki117

    Loki117 Guest

    You don't interact with it directly like that it's not how it works.
     
  7. Merlin2000

    Merlin2000 Active Member This Topic's Starter

    Joined:
    Nov 25, 2009
    Messages:
    31
    Likes Received:
    0
    So how do I view a db's scheme or change a value?
     
  8. Loki117

    Loki117 Guest

    You don't you create a SQLite DB in your own app space for your own application if you wish to uninstall apps or add contacts or any of that good stuff there is code to do it you don't interact with the DB's directly.

    Describe what you are trying to do and I may be able to help more clearly as talking in riddles means it takes 10 times as long.
     
  9. Merlin2000

    Merlin2000 Active Member This Topic's Starter

    Joined:
    Nov 25, 2009
    Messages:
    31
    Likes Received:
    0
    I'm not sure how else to explain it.. I want to access the database of an installed application.

    1. I install an application (such as one from the Android market)
    2. I want to access the installed applications database

    I'm not talking about my own application, I'm just talking about an installed application.
     
  10. regulatre

    regulatre Well-Known Member

    Joined:
    Nov 14, 2009
    Messages:
    46
    Likes Received:
    1
    Let's see if I understand what you're asking: There's an app installed on your phone which stores stuff in a database (all apps that use a database have their own database file under /data/data/<packagename>/...) . You would like to connect to that database and read/write the contents of it.

    Since each app's files (including its database) are owned by that app/user, that means other users/apps can't access each other's DB without administrative/super privileges.

    What you're looking for is a way to log in as a super user and access the sqlite databases used/owned by an app.

    The adb (Android debugger tool that comes with the Android SDK) has what you're looking for:

    Android Debug Bridge | Android Developers

    If you haven't set up Eclipse with the Android SDK I think that's where you would want to start. Alternatively you could try and find a way to get to a root shell and then run sqlite from the command line and pass it the database file name that you want to access (see the example in the adb link above). You could then run SQL queries against the database of your choice.









     
  11. Merlin2000

    Merlin2000 Active Member This Topic's Starter

    Joined:
    Nov 25, 2009
    Messages:
    31
    Likes Received:
    0
    That is exactly what I am trying to do. I already have Eclipse installed with the Android SDK. I've coded and installed my own programs before, but never done any database work.

    From what it sounds like, it isn't possible to view the database for a program unless I was the one who originally wrote it (and that program was installed from my computer). Is that correct?

    It does look like ADB provides shell access, so maybe my statement above is incorrect.

    I haven't seen anything substantial on rooting the Droid yet, so that is not currently possible.

    Thanks!
     
  12. regulatre

    regulatre Well-Known Member

    Joined:
    Nov 14, 2009
    Messages:
    46
    Likes Received:
    1
    There's lots of info for rooting on the developer101 sticky but I'm not a fan of rooting at this point. I just got my phone so I want to appreciate it for what it is before I try brain surgery on it.

    The sample in the ADB article above shows a "#" prompt once the shell is opened, which suggests the adb shell is root/superuser and that you could access the databases owned by other apps. But when I opened a shell, I just had regular privileges and not access to the databases (I couldn't even get a directory listing of /data/data). Let me know if you get it working!
     
  13. scorpicon

    scorpicon Member

    Joined:
    Nov 4, 2009
    Messages:
    17
    Likes Received:
    0
    There is no direct connection to a 3rd party's DB records. However, if an application sets up a Content Provider, you can access the data via that. Take a look at the documentation here: Content Providers | Android Developers

    Best of luck!
     

Share This Page

Loading...