- Home /
Android Persistent Data loading fails
Hey Everyone,
I'm struggling with a problem for a couple of days now, I'm making an app in which the user can take pictures with an AR layer and save them to a gallery for mobile devices.
To keep track of these pictures I make xml files with all the info the user enters and save this and the picture (which I take through a ReadPixels because I don't want my GUI in the picture) to the Application.persistentDataPath
This works perfectly in editor and iOS, but the Android version fails completely. Every time I try to load something it returns the error :
java.net.MalformedURLException: java.lang.NullPointerException: Cannot find "!/"
The address that I'm trying to open is: jar:file:///data/data/com.company.appName/files/name.txt
but neither the png or the txt loads and I have no idea why. I think the saving works which just saves it with fileStreamer to /data/data/com.company.appName/files/name.txt and I try loading it with a WWW, but that doesn't seem to work.
It's very confusing to find good information about the persistentdatapath and how to properly load from it and some say you have to add a prefix:
string path;
#if UNITY_EDITOR
path = "file:" + Application.persistentDataPath;
#elif UNITY_ANDROID
path = "jar:file://"+ Application.persistentDataPath;
#elif UNITY_IOS
path = "file:" + Application.persistentDataPath;
#else
//Desktop (Mac OS or Windows)
path = "file:"+ Application.persistentDataPath;
#endif
upon which I combine it with Path.Combine(path, fileName); And while this is the case for iOS, it hasn't worked so far I tried on Android and it's driving me nuts. I've tried it without the prefix, I've tried it with "jar:file/". Nothing seems to work, making me question this is even possible in Unity.
Is there something that has to be added to the manifest or changed in the player settings?
Please help, I'm losing too much time on this.
Answer by Studio-Raef · Dec 14, 2014 at 10:45 PM
Alright after trying it without the prefix, I got a different error, pointing me to someone else's solution, so I'm stating it here for anyone who's struggling with it.
if you want to load from persistent data on Android add the prefix:
#if UNITY_ANDROID
path = "file:///"+ Application.persistentDataPath;
This could be information that should best be added to the script reference.
not works for save csv file, what can i do for save csv file data?
I fought this for hours, thank you very much, now I can get my gif files properly.
Your answer
Follow this Question
Related Questions
Loading an image from streamingassets fails every time on Android 1 Answer
How to convert WWW type to FileStream? 1 Answer
Save an image to PersistentDataPath then access it again 1 Answer
PersistentDataPath saved files are not writing into android device? 1 Answer
Android : www.error 401 when using credentials in URL over HTTPs 0 Answers