This question was
closed Nov 23, 2015 at 12:43 AM by
auhan for the following reason:
The question is answered, right answer was accepted
Reading XML working in my computer but not in my Android phone
Hello friends,
Following code works perfect in my computer but when I try to run it in my Android Phone, it does not work.
string path = @"Assets\Layout\XML\file" + select.ToString() + @".xml";
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Name>));
StreamReader sr = new StreamReader(path);
List<Name> listnames = (List<Name>)xmlSerializer.Deserialize(sr);
How can I make the code work in my Android Phone?
Comment
Best Answer
Answer by auhan · Nov 23, 2015 at 12:43 AM
I almost gave up but finally solved it. Unity converts everything to binary variable so that the first thing you need to do is to convert all xml files you have to txt and copy them to "Assets/Resources" folder.
Then, you can use following code:
TextAsset asset = Resources.Load("file" + select.ToString()) as TextAsset;
Stream s = new MemoryStream(asset.bytes);
BinaryReader br = new BinaryReader(s);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Name>));
StreamReader sr = new StreamReader(s);
List<Name> listnames = (List<Name>)xmlSerializer.Deserialize(sr);
Follow this Question
Related Questions
Help me!!! Error not receiving image Unity3D. Please 0 Answers
"No Android Device Found" on Build and Run 1 Answer
Drag - Rotate 0 Answers
UNet Stunning an enemy player 0 Answers