Reputation: 175375
I'm trying to push a file to an Android device and then read it within a test app. It doesn't particularly matter where the file is, I can hardcode the path in the app, but the file has to be written to the device separately. If I push the file somewhere with adb
, it's owned by root with permissions 660 and the app can't open it. If I run-as
the app and try to read the file, I get "Permission denied". If I try to chmod the file I get "Operation not permitted". Is there some way to do this, other than rooting the device?
Upvotes: 2
Views: 2346
Reputation: 8416
You could utilize Application's Internal Private Storage (usually present under /data/local/
which has explicit adb shell user access).
In your case you can do it as below.
# 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
Tested on non-rooted Android phone.
Android OS : 5.0.2
ADB version : Android Debug Bridge version 1.0.31
Refer to the comments for this answer.
Upvotes: 3