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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

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

A phone network question!About GSM 、wifi and WWW! 0 Answers

Android Exception getInputStream() is not available 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges