How to Find my App's /data/data using Android

2019-03-18 17:15发布

I have an app that writes to text files onto Internal storage. I'd like to take a close look on my computer.

I ran a Toast.makeText to display the path, it says: /data/data/mypackage

But when I go to Android Studio's Android Device Monitor application, I don't see /data/data in the File Explorer. So where are my files?

I know they exist because I can find the on adb shell. I need to translate /data/data to a path visible on File Explorer, so that I can download them easily. Thanks!

5条回答
疯言疯语
2楼-- · 2019-03-18 17:41

You can only check that if you have a rooted phone, because these folders are private to applications and usual access is restricted to such folders. I would advise if you dont have a rooted phone then make a copy of your internal folders and write them to your SDCard to check the contents. The other way is to root your phone or use an Emulator.

Here is the code you can use to write a copy on your External SDCard:

public static void copyDirectoryOneLocationToAnotherLocation(File sourceLocation, File targetLocation)
            throws IOException {

        if (sourceLocation.isDirectory()) {
            if (!targetLocation.exists()) {
                targetLocation.mkdir();
            }

            String[] children = sourceLocation.list();
            for (int i = 0; i < sourceLocation.listFiles().length; i++) {

                copyDirectoryOneLocationToAnotherLocation(new File(sourceLocation, children[i]),
                        new File(targetLocation, children[i]));
            }
        } else {

            InputStream in = new FileInputStream(sourceLocation);

            OutputStream out = new FileOutputStream(targetLocation);

            // Copy the bits from instream to outstream
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        }

    }
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-03-18 17:54

You can use the adb console. Just write adb root and thenadb connect <IP>

After that you can open the data folder.

查看更多
可以哭但决不认输i
4楼-- · 2019-03-18 17:59

I think you're using API 24 or above, You must to create a new virtual device wihch does not API 24+

查看更多
何必那么认真
5楼-- · 2019-03-18 18:00

The /data/data folder is shown in my Android Device Monitor's File Explorer (Android Studio 1.4). At least for virtual devices.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-03-18 18:02

See this. Because /data/data is internal storage for the application itself, only apps with the same user id can acess it (or unless you have a rooted device).

查看更多
登录 后发表回答