I have an application in android
that makes use of the class SQLiteOpenHelper
to work a local database with 3 simple tables, to get the file MY_DATABASE.db
I use commands by ADB
of the next Form:
$ adb shell
shell@device:/ $ run-as com.my.package
shell@device:/data/data/com.my.package $ cp databases/MY_DATABASE /sdcard/MY_DATABASE.db
shell@device:/data/data/com.my.package $ exit
shell@device:/ $ exit
adb pull /sdcard/MY_DATABASE.db
My problem is that these commands do not work on all the devices I've tried:
Moto E (with root and without this) WORKS
Moto G (with root and without this) WORKS
Nexus 5x (with root and without this) DOES NOT WORK
Samsung J1 (without root) DOES NOT WORK
Samsung J2 (without root) DOES NOT WORK
Huawei (without root) DOES NOT WORK
What can I do to make the commands work for me on any device?
I managed to do this without any problem on all the devices mentioned above with this function:
public void copy(File src, File dst) throws IOException {
Log.d(TAG, "copying...");
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.d(TAG, "copied");
}
String strSrc = "/data/data/com.my.package/databases/MY_DATABASE"
String strDst = "/sdcard/MY_DATABASE.db";
File fSrc = new File(strSrc);
File fDst = new File(strDst);
try{
copy(fSrc, fDst);
}catch(IOException e){
Log.e(TAG, e.toString());
}
However I want to be able to do this process by ADB