1

I am saving an XML file to the internal storage of a device like so:

public void saveFriendData(FriendDetails friend, Context context) throws IOException 
{
        XmlSerializer serializer = Xml.newSerializer();
        StringWriter writer = new StringWriter();
        ContextWrapper wrapper = new ContextWrapper(context);

        File friendDir = wrapper.getDir("friend", Context.MODE_PRIVATE);
        File xmlFile = new File(friendDir, String.valueOf(friend.getId()) + ".xml");
        FileOutputStream os = new FileOutputStream(xmlFile);


        serializer.setOutput(os, "UTF-8");

        //start
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

        serializer.startTag("", "Friend");

        serializer.startTag("", "Id");
        serializer.text(String.valueOf(friend.getId()));
        serializer.endTag("", "Id");

        serializer.startTag("", "ImageUrl");
        serializer.text(friend.get_photoUri());
        serializer.endTag("", "ImageUrl");

        serializer.endTag("", "Friend");
        serializer.endDocument();

        serializer.flush();
        os.close();


    }

Once I had used the app I went into Windows Explorer, into the Android/Data directory, and a folder for my package where I would expect the XML to be saved is not there.

Can anyone explain where my XML is being saved to then? the directory the file is means to be saved to is as follows:

/data/data/com.test.test/

Thanks!

Tmarsh2
  • 417
  • 2
  • 16

2 Answers2

1

/data/ is private storage and is not accessible via MTP/Windows Explorer. This is by design and a security feature.

To access /data/ you will need to bypass this by having root.

Read more here

Community
  • 1
  • 1
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • Thanks for your reply. Is there a way I can look at the XMLs that my are saved to my phone? its for debugging purposes more than anything. Thanks. – Tmarsh2 Jun 07 '13 at 15:31
  • Don't write to internal storage, write to external storage. Then it will show up in Windows Explorer – Ken Wolf Jun 07 '13 at 15:32
  • There are many examples of this already, for example (http://stackoverflow.com/questions/5625315/how-to-create-a-file-in-an-sdcard-directory) – Ken Wolf Jun 07 '13 at 15:33
0

/data on the android is private and only the apps storing the data have access to the data (and only their own data). However you can write your files to /data/local/tmp/ folder. This is the only folder I know of (in /data) which allows read and write by anyone without rooting. You can connect your Nexus 4 via adb shell and pull your file from there. Remember that you have to reach the /data/local/tmp directory before ls starts working in android shell.

Srikant Sahay
  • 885
  • 6
  • 9