I’m fairly new to apk development. So far, after a book purchase and with a lot of Googling I’ve managed to make an application that controls some features of my custom ROM. I’m currently trying to implement 2 backup features. I want to backup /data/system/batterystats.bin to /sdcard and also i want to backup launcher.db of my touchwiz launcher to /sdcard.
For the first part i haven’t actually found anything. I’ve searched a lot about how to restore a file, not much has come up. It’s mostly about SQL .db files. I’ve also looked for the possibility to run a shell script via the apk just to perform this backup. With a shell script it’s easy work, but doing this via .java, i honestly have no clue.
Also, i’ve tried quite a lot of code to get my sqlite database file to backup, but i was quite unsuccessful. Here’s my code for you to look at:
public class Backup extends Activity {
public void exportDB(){
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
String currentDBPath = "data/data/com.sec.android.app.twlauncher/databases/launcher.db";
String backupDBPath = sd + "/launcher.db";
File currentDB = new File(currentDBPath);
File backupDB = new File(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) {
e.printStackTrace();
}
}
}
I have added permissions for external storage write, of course in the androidmanifest, but nothing happens. No FC, it just sits there doing nothing. And when I check my sdcard, there’s nothing there.
Any help would be greatly appreciated. Thanks
Download RootTools (the jar file).
You can then run linux commands like this:
RootTools.sendShell(command);For example to backup, you could do:
And to restore the file:
cp is the copy command, and -f is what allows it to overwite the file if it already exists.
RootTools are great, and for the commands, just google how to do linux commands and then place them into the
sendShellI have no idea how to do it with java. I personally think that using the linux commands are 10 times easier, though.
And to note, it is actually good to get sdcard location like this:
Environment.getExternalStorageDirectory();and then append the rest of the storage location info to the end of that.