0

I'm trying to load my image files on android which the images are on JSON. but I can't load any images on android .. In Unity, it is working fine but in Android nothing shows. why? what is the problem??

Here is the code for JSON to ANDROID, is there any incorrect I know there is and my conclusion is the Sprite to load image but how? any ideas?

myfilePath = "jar:file://" + Application.dataPath + "!/assets/TSdatabase.json";
        StartCoroutine(GetDataInAndroid(myfilePath));


IEnumerator GetDataInAndroid(string url)
{
    WWW www = new WWW(url);
    yield return www;
    if (www.text != null)
    {

        string dataAsJson = www.text;
        TSGameData myloadedData = JsonUtility.FromJson<TSGameData>(dataAsJson);

        myRoundData = myloadedData.myRoundData;
    }
    else
    {
        Debug.LogError("Can not load game data!");
    }
}

My code to image / sprite for JSON

private void LoadSprite(Sprite sprite) {
    MySprite.sprite = sprite;
    LoadSprite(MyQuestionImage.questionImage);
}

private void LoadSprite(string path)
{
    if (LoadedSprite != null)
        Resources.UnloadAsset(LoadedSprite);

    LoadedSprite = Resources.Load<Sprite>(path);

    MySprite.sprite = LoadedSprite;
}
make move
  • 11
  • 2
  • 9
  • What error do you get? At which line? – FaizanHussainRabbani Feb 24 '18 at 13:38
  • Where did you put the json files you are trying to load? – Programmer Feb 24 '18 at 13:47
  • I've edited the code above to show my json to image code in unity it shows very well but it does not show in android. – make move Feb 24 '18 at 14:09
  • @FaizanRabbani There is no error but the image I have in the JSON is not showing in android although it shows in Unity .. – make move Feb 24 '18 at 14:10
  • @Programmer kindly see the edited code above any solution will be helpful thank you, – make move Feb 24 '18 at 14:11
  • That did not really answer my question. I simply asked where you put the json file in your project..... – Programmer Feb 24 '18 at 14:13
  • I put it inside the StreamingAssets Folder. – make move Feb 24 '18 at 14:15
  • See my [answer](https://stackoverflow.com/a/47808399/3785314) here on how to read from the streaming asset folder.The `loadStreamingAsset` from that answer is all you need. Check if you can read your json file with that first. – Programmer Feb 24 '18 at 14:27
  • so if I added that i can view my image? – make move Feb 24 '18 at 14:36
  • so I can delete thos IEnumerator I have above the code? – make move Feb 24 '18 at 14:36
  • Sir? If you mid hehe @Programmer what can I fill in here ? filePath.Contains("://") I'm so sorry Im new to unity and all of this json :( – make move Feb 24 '18 at 14:37
  • I has nothing to do with images. It's simply loading the json file in your streaming assets folder. Do not modify that function. Leave it as it is. Replace it with your IEnumerator unction. That answer I linked also shows how to use it to load a json file. See if you can load your json file with it. – Programmer Feb 24 '18 at 14:40
  • Well, I need the image.. it does not work :( .. I think sprite must be concluded on the code but I have no knowledge on implementing it can you help me on that? – make move Feb 24 '18 at 15:00
  • Sounds like the same problem you were having yesterday or the same problem as your other 3 posts.. – AresCaelum Feb 24 '18 at 15:51
  • No, i'm really having a hard time. I've managed to solve those problem but this time I need to show images on the device... because on Unity it shows that image but when I build and Run it into the device the images are NOT showing. and I'm usign JSON as my datbase – make move Feb 24 '18 at 16:05

0 Answers0