- Home /
Load file on Android
Hey everyone,
I am trying to load xml files on android. Unfortunately android can't find the files, it does work on pc though. The code I'm using:
if (System.IO.File.Exists(getPath())) {
error.text = "File loaded";
path = getPath();
} else
{
error.text = getPath();
}
XmlReader reader = XmlReader.Create(path);
private string getPath()
{
#if UNITY_EDITOR
return Application.dataPath + "/Resources/Levels/" + level + ".xml";
#elif UNITY_ANDROID
return Application.streamingAssetsPath+"/Resources/Levels/"+level+".xml";
#elif UNITY_IPHONE
return Application.streamingAssetsPath+"/Resources/Levels/"+level+".xml";
#else
return Application.streamingAssetsPath+"/Resources/Levels/"+level+".xml";
#endif
}
The getPath() function returns the following path on Android: jar:file:///data/app/com.AzuryteGames.ColorZone-1/base.apk!/assets/Resources/Levels/Level01.xml
I have tried to use application.datapath and application.persistentdatapath but those also don't work.
Can someone help me with this? I have been trying to fix this for over a month now.
Answer by eclecticLoad · Dec 08, 2016 at 01:16 PM
Where did you save your xml files? Having xml files in the streaming assets folder and opening them with Application.streamingAssetsPath works fine for me
Your answer
Follow this Question
Related Questions
xmlDocument.loadXml/load raises NotImplementedException on android, works in editor 1 Answer
Help with Exception: Error building Player on Android 2 Answers
Hook before Assembly-CSharp.dll is loaded? 3 Answers
Trying to save and load from a text file on android. 3 Answers
Where can I put xml on android? 1 Answer