Cant save file into Android internal memory
Hi, i have a problem saving xml / txt / whatever, into the internal memory of android, my cellphone is a moto x first gen, so it does not have sd card
this is my code:
new XDocument( new XElement("PIF", new XElement("someNode", "someValue")
) ) .Save(Application.persistentDataPath + "name.txt");
In windows generates the following txt:
someValue
But in android nothing happens. I tried root browsers and nothing. Nothing is saved.
Any help?
oh i forgot to mention that i tried Application.DataPath and the write acces in external and in internal, and nothing happens
Answer by dishant27 · Feb 24, 2018 at 05:18 PM
string path = "/storage/emulated/0/"; string folderName = "xyz"; void Start() { if(!Directory.Exists(path + folderName)) { Directory.CreateDirectory(path + folderName); } SaveFile(AndroidText); }
void SaveFile(string fileName) { System.IO.File.WriteAllText(path + folderName + "/" + fileName +".txt", "Congrats! It's saved"); }
// You can find the created folder in your phone's memory