我正在尝试将文件推送到 Android 设备,然后在测试应用程序中读取它。文件在哪里并不特别重要,我可以在应用程序中硬编码路径,但文件必须单独写入设备。如果我使用 adb
将文件推送到某处,则该文件由 root 拥有,权限为 660,并且应用程序无法打开它。如果我run-as
应用程序并尝试读取文件,我会收到“权限被拒绝”。如果我尝试 chmod 该文件,我会收到“不允许操作”。除了 root 设备之外,还有其他方法可以做到这一点吗?
最佳答案
您可以利用应用程序的内部私有(private)存储(通常位于具有显式 adb shell 用户访问权限的 /data/local/
下)。
根据您的情况,您可以按照以下方式进行操作。
# Create your file (On Host PC) #
$ touch hello.txt
# Push it to the device (If the below path doesnt exist, it will create it) #
$ adb push hello.txt /data/local/tmp
0 KB/s (14 bytes in 0.043s)
# Switch to ADB Shell #
$ adb shell
# See Permissions before applying chmod #
shell@android:/ $ ls -l /data/local/tmp/
-rw-rw-rw- shell shell 14 2015-07-14 15:35 hello.txt
# Change permissions using chmod #
shell@android:/ $ chmod 777 /data/local/tmp/hello.txt
# See Permissions after applying chmod #
shell@android:/ $ ls -l data/local/tmp/
-rwxrwxrwx shell shell 14 2015-07-14 15:35 hello.txt
在未 root 的 Android 手机上测试。
Android OS : 5.0.2
ADB version : Android Debug Bridge version 1.0.31
引用此评论answer.
关于android - 将应用程序可读的文件推送到 Android 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31390118/