Save file on phone instead of SD card

In my application, I save the XML file on the user's SD card by doing File newxmlfile = new File(Environment.getExternalStorageDirectory() + "/Message.xml");

But not all users have SD cards in their phone, and so my application is likely to crash.

How do I change the way I create a file to save the file to my phone instead of the SD card?

Also, how do I change the file upload? (at present time new InputSource(new FileInputStream(Environment.getExternalStorageDirectory() + "/Message.xml")))

EDIT: I don't think you have a question correctly. I know the data storage page in Docs for Android, and I read it. I just want to know how I can configure it to fit my current way of saving and loading a file.

+3
source share
4 answers

Get it by changing

Environment.getExternalStorageDirectory() + "/Message.xml"

at

Environment.getDataDirectory() + "/data/com.companyname.appname/files/Message.xml"
+4
source

andriods Data-Storage.

, .

+2
+1

Source: https://habr.com/ru/post/1785149/


All Articles