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 Riyria · Jan 13, 2015 at 11:51 AM · c#androidxml

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.

Comment
Add comment · Show 2
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 CodeMasterMike · Jan 13, 2015 at 12:25 PM 0
Share

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.

avatar image AndresBarrera · Jan 13, 2015 at 02:34 PM 0
Share

If you want to debug on Android follow these steps (from the top of my head):

  1. $$anonymous$$ake sure your PC recognizes the device through USB.

  2. Allow USB Debugging on the device.

  3. 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.

  4. 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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Save and Load data from Local XML file won't work 1 Answer

How can I read an XML file in Android ? I can't access it 1 Answer

how can i deserialize xml to vector4 List?? 0 Answers

AssetBundles are not working outside editor on PC or Android. 1 Answer

Multiple Cars not working 1 Answer


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