0

I'm using xamarin forms to develop an Android app. I can save a file via

    var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), $"appsettiings.txt");
    var data = JsonConvert.SerializeObject(this);
    File.WriteAllText(fileName, data);

When I debug I can see that the file should be stored at

/data/user/0/<applicationame>/files/.local/share/appsettiings.txt

I like to see if the file is actually saved and what the content is. I opened the Android device monitor but the data folder was 'empty'. From some other SO case I took that I should but myself in root-mode by executing

C:\Program Files (x86)\Android\android-sdk\platform-tools>adb root

Now the data folder contains data and I can drill down up to the files folder, but that one seems to be empty.

When I run the app again and check in code if the file exists, it actually does.

Any further suggestions how to get access to that file from any tooling. I want to delete that file and run the app again.

BrilBroeder
  • 1,409
  • 3
  • 18
  • 37

2 Answers2

6

You can use adb pull to copy the file to local machine and look at it content like this:

adb root
adb pull /data/user/0/<applicationame>/files/.local/share/appsettiings.txt [LOCAL_FOLDER]

then you can use adb shell then rm -f to remove it, like this:

adb shell
su
rm -f /data/user/0/<applicationame>/files/.local/share/appsettiings.txt 

Since the file you are requesting is inside /data folder, you need to have the corresponding root priviliege to get it, so you need to do adb root before the adb pull command, and you need to do su before removing the file.

Jack
  • 5,354
  • 2
  • 29
  • 54
  • The command `adb root` does not work on all emulators. See https://stackoverflow.com/questions/43923996/adb-root-is-not-working-on-emulator-cannot-run-as-root-in-production-builds – SymboLinker Apr 06 '23 at 09:10
0

If I am not mistaken, if you save a file with your approach, it should exist, as you already proofed with the .Exists method.

I am not quite sure, are you just trying to read the content out of the file? Or do you want to access it from outside of the application?

If your desire is to just read the content, you could access it with

string content= File.ReadAllText(your file path);

and set a breakpoint (F9) on the next line.

Robert Haslinger
  • 155
  • 1
  • 17
  • Reading and writing the file from the Xamarin app is working fine. But for debug puposes I would like to open the file using the Android Device Monitor. – BrilBroeder May 04 '19 at 17:10