Home > front end >  Unity, android data folder empty
Unity, android data folder empty

Time:09-17

I can't fix a problem with JSON files on an Android device.

In Unity Project - Assets, I created the "StreamingAssets" folder and inside there is a .json file (data.json). Once the app is installed on my android device and going to the folder "/storage/emulated/0/ Android/data//files" there is no json file that I put in the "StreamingAssets" folder. What am I doing wrong?

CodePudding user response:

Here's what I do to get the Languages text from Language.json file in StreamingAssets

IEnumerator LoadLocalizedText(Action<bool> success)
    {
        string filePath = Path.Combine(Application.streamingAssetsPath, "Language.json");

        string dataAsJson = "";

        //Android
        if (filePath.Contains("://"))
        {

            WWW reader = new WWW(filePath);

            //Wait(Non blocking until download is done)
            while (!reader.isDone)
            {
                yield return null;
            }

            if (reader.text == null || reader.text == "")
            {
                success(false);

                //Just like return false
                yield break;
            }

            dataAsJson = reader.text;
        }

        //iOS
        else
        {
            dataAsJson = File.ReadAllText(filePath);
        }


        jsonString = dataAsJson;

        if (dataAsJson == "") 
        {
            success(false);
            UpdateLanguage(PlayerPrefs.GetString("Language", "SP"));
        }

        else
        {
            success(true);
        }
    }
  • Related