mercredi 4 mai 2016

Running a shell command in Android to access a 3rd party app Database

I am trying to access a database of another app (a messaging app) through a shell command (as is my understanding that this is the only way to do it if it's a 3rd party app without ContentProvider?)

I have root on my device, but I get this error when I click the button:

05-04 15:42:10.993 1246-1246/com.dysanix.official I/System.out: 0Unknown id: sqlite3


public void buttonConnectDatabase(View v) {
        int lastId = runCommandInt("select _id from messages order by _id DESC LIMIT 1;");

public static int runCommandInt(String arg1) {
    try {
        Process p = Runtime.getRuntime().exec("su sqlite3 -csv /data/data/com.package/databases/database.db '" + arg1 "'");
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        String s = null;
        int i = 0;
        while ((s = stdInput.readLine()) != null) {
            i = Integer.parseInt(s);
            return i;
        while ((s = stdError.readLine()) != null) {
    } catch (Exception e) {
    return 0;

I tried Googling the problem, I tried looking for alternatives to directly read a 3rd party app database (which I would very much prefer over this), but I cannot find any solutions as to why this problem arises.

If someone could help me, it would be greatly appreciated. :-)

Aucun commentaire:

Enregistrer un commentaire