Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to load a .xml file in Android?

Discussion in 'Android' started by luoyu510183, Apr 16, 2019.

  1. luoyu510183

    luoyu510183

    Joined:
    Dec 25, 2018
    Posts:
    18
    I place a "strings.xml" file in the StreamingAssets folder because I want to load some parameters from it. But I failed to load this .xml file. I tried to load this file by System.IO, the path of it is Application.streamingAssetsPath + "/XML/strings.xml", and failed. Also, I tried to load this file by WWW, the path of it is "file://"+Application.streamingAssetsPath + "/XML/strings.xml", and failed.

    Also, I notice that the WWW is already obsolete in Unity2018.3. So what's the best way to load this config file in Android(API>=24)?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    UnityWebRequest is a replacement for WWW.
     
  3. luoyu510183

    luoyu510183

    Joined:
    Dec 25, 2018
    Posts:
    18
    I figured out that my problem was caused by the utf-8 BOM of the .xml file. And I should use WWW class, the path is Application.streamingAssetsPath + "/XML/strings.xml", to open any file in the StreamingAssets folder.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    You can also read streaming assets using UnityWebRequest (since 2017.1).
     
    luoyu510183 likes this.