I'm trying to access a database using root and sqlite3 to get data from it.
So far I managed to display data in the logcat but I can't get it in a file or any other way.
Using RootCommand library this is my code :
public void readDB(String message){
try {
Shell shell = Shell.startRootShell();
String setOutput= "sqlite3 .output /sdcard/number.txt"; // This didn't work because it treats .output as a database name
String readTest = "sqlite3 /data/data/com.package/databases/someDB.db \"SELECT * FROM table\";";
shell.add(new SimpleCommand(setOutput)).waitForFinish();
shell.add(new SimpleCommand(readTest)).waitForFinish();
Log.d(TAG , "finished");
} catch (IOException | TimeoutException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
}
As explained here I used .output
to specify a file but it didn't work because it treats .output
as a database name and throws an exception that it can't find the db and continues to display results in logcat.
And I tried writefile('/sdcard/myfile.txt',column)
but no file and no data in logcat.
When I try .output /sdcard/myfile.txt
from adb it works fine and I find the results in the file but I can't get it done through the code
So how to get this data in anyway? Is there any better approach to do this?
PS: I'm not accessing my own app data so I can't use sqlite database helper class.