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
Code:
public void buttonConnectDatabase(View v) {
int lastId = runCommandInt("select _id from messages order by _id DESC LIMIT 1;");
System.out.print(lastId);
}
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);
p.destroy();
return i;
}
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
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