Reputation: 21
My APP need root privileges to do some analysis , so I write in my code as
" Runtime.getRuntime().exec("su");
" ,then write linux command or shell script into it.
I tried to copy /data/data/packagename/databases/webview.db files to /sdcard/test (the source database files is all the app data files exists in my cellphone , though java code I can only get the file of my app itself ),
and then do some analysis.But the trouble is ,the source files name are the same, if I use
“cp -r /data/data/*/webview.db /sdcard/test
"
there is always only one file in the target directory,I was not so good at linux shell
command, so I want to know how to copy to the target directory and change the filename or just
keep the source directory structure like /sdcard/test/package/webview.db . I'm Chinese and my
English is not so well, hope you can understand it ,Thank you !
Upvotes: 1
Views: 9306
Reputation: 1525
i am using this code and it's working great!
public void copyDbToSdcard() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + this.getPackageName()
+ "//databases//db";
String backupDBPath = Environment.getExternalStorageDirectory()
.toString() + "/Darama1/db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB)
.getChannel();
FileChannel dst = new FileOutputStream(backupDB)
.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
}
Upvotes: 2
Reputation: 3756
You can use adb.
Once you USB connect your device
you run:
adb -s YOURDEVICE pull /data/data/packagename/databases/webview.db
to know what your device is
you run:
adb devices
Doing so you have your webview.db file on your desktop and you can use it as you like
Upvotes: 0