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 sandeepsmartest · May 12, 2014 at 06:57 PM · androidwwwxmltextasset

Guys please help me!!how to download xml file from url in android device runtime

Basically i want to read data from url and store it to xml file during runtime in android device.So that i can use the xml file in further reference in my android apk

And one more doubt -how to convert string to text asset

Below is a small trail that i did for xml download,but of no use

 public class XmlTest : MonoBehaviour {
     
         public  XmlDocument DataFrmOnline;
          string url;
         public string[] str;
         public string str1;
          public TextAsset xmltextasset;
     // Use this for initialization
     
         void Start () {
        url="myurl/apps.xml";
     }
      // Update is called once per frame
     
         void Update () {
     
             if(Input.GetKeyDown(KeyCode.A))
       StartCoroutine(IsFinishDownload(url));
     }
     
         IEnumerator IsFinishDownload (string url) {
              WWW hs_get = new WWW(url);
               yield return hs_get;
              str1= hs_get.text;
            try
            {   
               DataFrmOnline = loadxmldocu(hs_get.text);  //this works good if i input       textasset instead of www.text
            }
          catch{}   
       }
     
         public static XmlDocument loadxmldocu(TextAsset xmlfile)
     
         {
             MemoryStream assetstream = new MemoryStream (xmlfile.bytes);
             XmlReader reader = XmlReader.Create(assetstream);
             XmlDocument xmlDoc = new XmlDocument();
             xmlDoc.Load(reader);
             return xmlDoc;
      }
     
    }
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
0
Best Answer

Answer by sandeepsmartest · Oct 21, 2015 at 07:08 AM

 public Texture2D TextureContainer;
     void Start()
     {
         StartCoroutine(FinishDownload_Image("ImageUrl",TextureContainer));
     }
 IEnumerator  FinishDownload_Image (string url,Texture2D TexturToCopy, int no) {
         WWW hs_get2 = new WWW(url);
         
         yield return hs_get2;
         //sun= hs_get.texture;
         
         //hs_get.LoadImageIntoTexture(TexturToCopy);
         //print("image url finsh__"+url);
         TexturToCopy= hs_get2.texture;//TexturToCopy-consists of image that resides in the url
         
         
         
     }
Comment
Add comment · Show 1 · 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 fafase · Oct 21, 2015 at 11:31 AM 0
Share

This is not about to work as you expect it.

TextureToCopy is of type Texture2D and when you pass the TextureContainer argument, the value is passed. So if TextureContainer is 0x00AA then TextureToCopy is 0x00AA.

Then you pass a new texture to it that is actually created by Unity somewhere else. So TextureToCopy is now 0x00BB but TextureContainer has not changed.

You need to use a delegate:

 IEnumerator  FinishDownload_Image (string url,Action<Texture2D> action, int no) {
      WWW hs_get2 = new WWW(url);
      yield return hs_get2;
      action(hs_get2.texture); 
  }

and you call

  void Start()
  {
      StartCoroutine(FinishDownload_Image("ImageUrl", result => TextureContainer = result));
  }

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

20 People are following this question.

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

Related Questions

ArgumentException: Path is empty while saving data in an XML 0 Answers

How to read xml file on Android using www and StreamingAssets? 2 Answers

WWW http request loads way to long on IOS 0 Answers

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

Handle HTML response 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