备份/data/system/xxxx.bin到/sdcard

发布于 2024-12-17 06:00:40 字数 1368 浏览 0 评论 0原文

我对 apk 开发还很陌生。到目前为止,在购买一本书并进行大量谷歌搜索后,我已经成功制作了一个应用程序来控制我的自定义 ROM 的某些功能。我目前正在尝试实现 2 个备份功能。我想将 /data/system/batterystats.bin 备份到 /sdcard,还想将 touchwiz 启动器的 launcher.db 备份到 /sdcard。

对于第一部分,我实际上还没有找到任何东西。我搜索了很多有关如何恢复文件的信息,但没有找到太多内容。主要与 SQL .db 文件有关。我还寻找通过 apk 运行 shell 脚本来执行此备份的可能性。使用 shell 脚本很容易工作,但是通过 .java 执行此操作,我真的不知道。

另外,我尝试了很多代码来备份我的 sqlite 数据库文件,但我非常不成功。这是我的代码供您查看:

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();
    }
}

}

我添加了外部存储写入权限,当然是在 androidmanifest 中,但没有任何反应。没有 FC,它只是坐在那里什么也不做。当我检查我的 SD 卡时,那里什么也没有。

任何帮助将不胜感激。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莫言歌 2024-12-24 06:00:40

下载 RootTools(jar 文件)。

然后,您可以像这样运行 Linux 命令:

RootTools.sendShell(command);

例如,要备份,您可以执行以下操作:

RootTools.sendShell("cp -f /data/data/com.sec.android.app.twlauncher/databases/launcher.db /sdcard/directory/");

恢复文件:

RootTools.sendShell("cp -f /sdcard/directory/launcher.db /data/data/com.sec.android.app.twlauncher/databases/");

cp 是复制命令,-f 是允许的命令如果文件已存在,则覆盖该文件。

RootTools 很棒,对于命令,只需谷歌一下如何执行 linux 命令,然后将它们放入 sendShell

我不知道如何用 java 来做到这一点。不过,我个人认为使用 linux 命令要容易 10 倍。

需要注意的是,像这样获取 SD 卡位置实际上很好:
Environment.getExternalStorageDirectory();

然后将其余的存储位置信息附加到其末尾。

Download RootTools (the jar file).

You can then run linux commands like this:

RootTools.sendShell(command);

For example to backup, you could do:

RootTools.sendShell("cp -f /data/data/com.sec.android.app.twlauncher/databases/launcher.db /sdcard/directory/");

And to restore the file:

RootTools.sendShell("cp -f /sdcard/directory/launcher.db /data/data/com.sec.android.app.twlauncher/databases/");

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 sendShell

I 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文