'PersistentDataPath file is not working on device but fine in unity 3d
xml.Load(Application.persistentDataPath+"/PlayerData.xml");
XmlNode root = xml.FirstChild;
root = xml.LastChild;
if(root.InnerText == "")
{
lnoInstance.EnlistAllLevels();
foreach(LevelNamesStatus lno in LevelLoadingArray )
{
XmlNode child = CreateNode(xml,lno.Lname,lno.winStatus,lno.playingStatus);
root.AppendChild(child);
}
}
else
{
if(LevelLoadingArray.Count!=0 && LevelLoadingArray.Count<=13)
{ LevelNamesStatus[] array = CtrlLLoadingA.LevelLoadingArray.ToArray();
foreach(LevelNamesStatus n in array)
{
// Debug.Log(n.Lname+n.playingStatus);
}
foreach(XmlNode xmn in root)
{
xmn.ChildNodes[0].InnerText = LevelLoadingArray[f].Lname;
xmn.ChildNodes[1].InnerText = LevelLoadingArray[f].winStatus.ToString();
xmn.ChildNodes[2].InnerText = LevelLoadingArray[f].playingStatus.ToString();
f++;
}
}
if( LevelLoadingArray.Count==0)
{
RefillArray(root);
}
}
xml.Save(Application.persistentDataPath+"/PlayerData.xml");
Unable to fetch xml file at persistentDataPath .. It's working fine on unity 3d but device or simulator is not able to fetch that xml file.. StorageExceptError is being held at runtime on device
Solution 1:[1]
It is always recommended not to use '/' or '\' chars hardcoded anywhere. Instead please try using Path.DirectorySeparatorChar (See Unity docs).
In this case it should be:
xml.Load(Application.persistentDataPath + Path.DirectorySeparatorChar + "PlayerData.xml");
Then you can be certain that on all kind of devices or platforms at least the path will be correct.
Solution 2:[2]
Application.persistentDataPath have two paths base on your Write Access setting, you can find it at Build Setting > Player Setting > Other Settings, by default, it is internal Only. means that the path should be point to /data/data/com.your.appid/files which is for development only, user cannot find this files without root android device.
if you set the Write Access as External(SD Card) or add WRITE_ EXTERNAL_STORAGE permission into AndroidManifest.xml, Application.persistentDataPath will point to Android/file/com.your.appid/files of your sd card.
I had same problem and this fixed it!
http://answers.unity3d.com/questions/203852/how-to-access-persistent-data-path-in-android-phon.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kreys |
| Solution 2 | Savas Adar |
