user6009023
user6009023

Reputation:

Show Android internal storage file in Android Studio

Currently I have an app that I am developing that uses the following code to test whether or not a file exists and if the file does not, it is created and stored in internal storage.

public void linkToFile()
    {

        if(checkFileExists() == true)
        {
            System.out.println("Contacts file exists, reading file");
        }
        else
        if(checkFileExists() == false)
        {
            System.out.println("Contacts file does not exist, creating file");

            try
            {
                FileOutputStream fileOutputStream = openFileOutput(cFile, Context.MODE_PRIVATE); //Creates contactFile.txt in internal storage
                System.out.println(cFile + " file created.");
            }
            catch(java.io.FileNotFoundException e)
            {
                System.out.println("File not found exception");
                e.printStackTrace();
            }

        }


    }

This all works completely fine and as it should. However I have an issue in that I want to be able to view the contents of the file that is created at runtime. The app I am creating is a contacts app and therefore it would aid me greatly in being able to read the contents of the file whilst the application is running so that I can see what is being produced and stored in the file by the application, otherwise I'll be trying to develop this blind and it'll be much harder to do.

Is there a way in Android studio for me to be able to see which files are created by the app and stored in the internal storage at runtime? A file explorer or something for example? I'm not talking about being able to read the contents of the text file using java code, I'm talking about actually opening the created file like you would using Finder on Mac or Explorer on Windows, but in Android Studio if that is possible?

Upvotes: 2

Views: 12638

Answers (2)

Mijo
Mijo

Reputation: 611

In Android studio 3.3 you can go to view => Tools Window => Device file explorer. That would show you the device files. Please note that if you are using a Samsung phone for debugging,

If you have a SAMSUNG device, don't bother - SAMSUNG broke run-as by dropping the setuid flag (so run-as has no chance of switching to a different identity).

Also don't bother trying the Smart Switch "reinitialize device" workaround, it won't work until SAMSUNG fixes it in the firmware (so it is worth updating to the latest version).

Use some other method to access your app's data, like adb backup:

adb backup -f data.ab dd if=data.ab bs=24 skip=1 | openssl zlib -d > data.tar

Please see run-as: Could not set capabilities: Operation not permitted

Upvotes: 6

Pavel B.
Pavel B.

Reputation: 824

In Android Studio: Tools -> Android -> Android Device Monitor.

After device monitor started, in Android Device Monitor window: File Explorer tab, then find Your file, then press pull from device.

Upvotes: 2

Related Questions