- Home /
Baffled by Android storage system...
So, I am entirely confused by the whole PersistantDataPath/StreamingAssetPath/DataPath set up, and I'm not sure what one to use, or how to use it...
I have what I want running in editor perfectly, but its not working on my android builds and I'm not sure why..
When the program boots up, it loads in data from and xml(In the Assets root folder) to make a visible list of sorted objects, users have the ability to favorite certain objects, and on doing so it should re-sort the list, and save out the data in the xml again and have that same edited list remain on multiple launches.
I guess some of my code might help if im doing something glaringly wrong :S
Read In
public void ReadIn(string soundType)
{
string _bytePath;
if(Application.platform == RuntimePlatform.Android)
_bytePath = Application.persistentDataPath + "/" + soundType + "Bytes.xml";
else
_bytePath = Application.dataPath + "/" + soundType + "Bytes.xml";
XmlDocument _byteXml = new XmlDocument();
_byteXml.Load(_bytePath);
XmlElement xRoot = _byteXml.DocumentElement;
XmlNodeList xNode = xRoot.SelectNodes("/ByteList/Bytes/Byte");
foreach(XmlNode _xNode in xNode)
{
string _nam = _xNode.Attributes[0].InnerText;
string _dir = _xNode.Attributes[1].InnerText;
float _len = float.Parse(_xNode.Attributes[2].InnerText, System.Globalization.CultureInfo.InvariantCulture);
bool _fav = Convert.ToBoolean(_xNode.Attributes[3].InnerText);
_byteArray.Add(new ByteInfo(_nam, _dir, _len, _fav));
}
}
Write Out
public void WriteOut(string soundType)
{
string _bytePath;
var serializer = new XmlSerializer(typeof(ByteList));
if(Application.platform == RuntimePlatform.Android)
_bytePath = Application.persistentDataPath + "/" + soundType + "Bytes.xml";
else
_bytePath = Application.dataPath + "/" + soundType + "Bytes.xml";
using(var stream = new FileStream(_bytePath, FileMode.Create))
{
serializer.Serialize(stream, this);
}
}
I might have been able to figure this out if I had any idea how to debug on an android.. currently I'm just changing minor things, rebuilding then testing it on my phone :S Any help appreciated.
Are you writing to a SD card? If so, check so that you have the permissions to write to a external source in the android manifest.
If you want to debug on Android follow these steps (from the top of my head):
$$anonymous$$ake sure your PC recognizes the device through USB.
Allow USB Debugging on the device.
Opend a Command Prompt on your PC and navigate to the folder where you installed the Android SD$$anonymous$$, and then to the folder "platform-tools" inside it.
Write: adb logcat -s Unity, and hit enter
If everything goes fine (and if I'm not forgetting any step) you should be able to see Debug.Log messages on the command prompt when running the application on the Android.
On another note, I know that you can load assets and X$$anonymous$$Ls from the Resources folder on Unity without problems on any platform, but I'm not sure if you can rewrite them. In case you can, maybe you can try doing the whole process with Resources