3

i'm trying to get an app started so I can backup my apps to sdcard. I ran:

        Process p = Runtime.getRuntime().exec("su");
    Process c = Runtime.getRuntime().exec(
            "cp /data/app/com.ebay.mobile-1.apk"
                    + Environment.getExternalStorageDirectory()
                    + "/ebay.apk");
    Log.d("copy", "done");

When it runs I can grant super user then it says it's done but there is no file is not copied. I'm just using the eBay app as an example and test.

Thanks for any help.

Fix: thanks for the help below but i found a full fix and kinda different way of doing things here "http://stackoverflow.com/questions/10735273/copy-folders-in-data-data-to-sdcard-viceversa?rq=1"

4

2 回答 2

7

Android 不支持cp命令。为此,您必须使用cat命令(仅来自 shell),

cat source_file > dest_file

或者在您的应用程序中使用BusyBox 。

编辑:

你也可以使用命令,

dd if=source_file of=dest_file
于 2012-07-03T16:10:45.413 回答
0

这个 QA 帮助了我很多,所以我想在各种 exec 答案中添加一些东西。与其使用 Runtime.getRuntime().exec(String),不如考虑使用 Runtime.getRuntime().exec(String[])。这应该可以防止带有空格的文件路径对您的文件系统造成严重破坏。

尝试

Process copy = Runtime.getRuntime().exec(
new String[]{
    "dd", 
    "if=" + inputFile.getAbsolutePath(), 
    "of=" + outputFile.getAbsolutePath()
});
于 2015-08-28T18:18:56.750 回答