Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Studio-Raef · Dec 14, 2014 at 10:04 PM · androidwwwloadingpersistentdatapathfilestream

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Xigna · Apr 10, 2016 at 09:01 AM 0
Share

not works for save csv file, what can i do for save csv file data?

avatar image Chamandana · Jun 22, 2016 at 07:49 AM 0
Share

is this path correct, "file:///storage/emulated/0/"?

avatar image Horothenic · Jan 14, 2018 at 04:59 AM 0
Share

I fought this for hours, thank you very much, now I can get my gif files properly.

avatar image abendiix · Feb 18, 2020 at 12:33 PM 0
Share

Thank you so much! Works even for Windows. ^^

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges