Viewing private files created by an android app

后端 未结 5 1030
情歌与酒
情歌与酒 2021-02-04 01:53

I have an xml file being written by an app that is set to MODE_PRIVATE, but I now want to read that file outside of the phone, for debugging purposes. In Eclipse, I can access o

相关标签:
5条回答
  • 2021-02-04 02:32

    If Eclipse is used, there is one more option:

    DDMS Perspective > File Explorer tab > data/data/com.yourpackage.yourapp/files

    where you can pull/push/delete files.

    0 讨论(0)
  • 2021-02-04 02:33

    You will need to connect the phone and do some magic to let your sdk work with it (I think put it in debugging mode?). Go to where you unzipped the android sdk:

    C:\android-sdk_r10-windows\android-sdk-windows\platform-tools>adb shell
    #cd data/data/com.yourpackage.yourapp/files
    #ls
    

    You should see your file listed. You may need to run "ls data/data" if you're not sure what the fully-qualified name of your app is. From here if the file is small and you just want to see what's inside it you can run:

    #cat yourfilename.xml
    

    Alternatively:

    #exit
    C:\android-sdk_r10-windows\android-sdk-windows\platform-tools>adb pull /data/data/com.yourpackage.yourapp/files/yourfile.xml
    

    Note: I have only tried this on the emulator, I don't know how to use adb with a physical phone.

    0 讨论(0)
  • 2021-02-04 02:36

    You need to root your phone to see Context.MODE_PRIVATE files

    It ends up being stored in data//files I believe but you need root permission to see them

    So either root your phone or wait until you finished debugging and then add Context.MODE_PRIVATE

    0 讨论(0)
  • 2021-02-04 02:46

    If your app is installed in debug mode, you can get your private files on a device without rooting.

    1. Go to [android-sdk]/platform-tools folder and run adb shell.
    2. run-as com.example.yourapp
    3. cp -r /data/data/com.example.yourapp /sdcard/

    (Where com.example.yourapp is the package name of your application.) After executing the steps above, the private folder of your application is copied into the root of your sdcard storage, under your package name, where you have permission to download and view them.

    Note 1: If you don't need to download them, then instead of step 3, you can use unix commands to navigate around and list files and folders.

    Note 2: Starting from Android Studio 2.0, you'll find more files in the cache and files/instant-run folder, related to the Instant Run and the GPU Debugger features, placed there by the IDE.

    0 讨论(0)
  • 2021-02-04 02:57

    Another option is to have a command in the app that dumps the private files. This only works if you don't want to edit the files, but has the added bonus that you don't have to strip it out before it goes to production, because the user can't break anything with it. Well, as long as the files don't contain sensitive information. But, really, if they do, you're doing something wrong. As @user1778055 said, a user can root their phone to access it.

    0 讨论(0)
提交回复
热议问题