简体   繁体   中英

How do I get the files I stored with my app (Android) on my PC?

I created json files on the internal (private) storage of the app I write for my Google Nexus 5 .

I was told, that this is the so-called private app space which I cannot access from my PC unless I either root the phone (not an option) or use the work-around by making backups via adb.

I tried to get access via adb shell . But whenever I try to access the `data? directory I am being told I don't have permissions to access that directory.

How do I get access to this directory and to my files?

Note: I also was told that I should try to use Environment.getExternalStorageState() instead of writing into the private app space. But when I try to write to /storage/emulated/0/ it just won't work either.

I don't care which approach to use, I just need access to the files I create on my PC asap.

You can use the Android Device Monitor to get access to private application spaces, in rooted devices and emulators (All emulators including Genymotion and AVD are rooted by default)

To write your files on the external storage, don't forget to declare the permission in the AndroidManifest.xml :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Since this permission is categorized as dangerous in Android 6.0, you should explicitly request for accessing it. More on permission.

If you can't or you don't want to root your physical phone, you can write the files on the external storage and access them on your PC.

If you want to write file on SDCard then you need to obtain permission to write data on SDCard.

Here is a way to obtain permission:

AndroidManifest.xml

<manifest ...>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    ...
</manifest>

If you want to support Marshmallow(API-23) then you need to obtain this permission runtime.

for that ref a link : https://developer.android.com/training/permissions/requesting.html

First get runtime permission using this command.

adb shell pm grant com.package.app android.permission.<PERMISSION>

Example

adb shell pm grant com.package.app android.permission.CALL_PHONE

then you can have access to storage.

This did the job:

adb shell
run-as PACKAGE.NAME
chmod 771 files
cp files/*.json /sdcard/<SOME_DIR>
adb pull /sdcard/<SOME_DIR> <SOME_LOCAL_DIR>

other possible solution that also worked for me:

adb backup -noapk PACKAGE.NAME
dd if=backup.ab bs=24 skip=1|openssl zlib -d > backup.tar
tar -zxvf backup.tar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM