- Home /
Is it possible to connect a 000webhost website in an android app?
I'm doing an Android application with unity where a user can view infro from certain events in their city (like fairs, movies, etc).
The way it works is that I have a website where an admin can change information about these events and then is updated in the app. The app requests the info from the website that is sent in a JSON (this json has the title of the event and the description).
And, from the user viewpoint, he sees a text that says "charging text" for a couple of seconds and then it changes to the description. And this works when I use the unity editor. But when I install the APK in my phone, it doesn't works, instead it stays in the "charging text" message eternally, wich, according to my code, is because of a connection error, that my app couldn't het the json from the website.
The curious thing is that, I do can open the website with the app(opens the browser), but not get the json from it.
Is it because i'm using 000webhost? (a free hosting) or is it because i'm forgetting something in my code/build settings?
Here is the code if there is something wrong here:
[Serializable]
public class PlaceInfo
{
public string Titulo = "";
public string Texto = "";
}
public string URL;
public Text TituloUI;
public Text TextoUI;
public PlaceInfo placeInfo;
public void Start()
{
if (Debug.isDebugBuild)
{
StartCoroutine(GetRequest(URL));
}
}
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
string jsonForm = uri;
if (webRequest.isNetworkError)
{
Debug.Log("Error loading");
}
else
{
try
{
placeInfo = JsonUtility.FromJson<PlaceInfo>(webRequest.downloadHandler.text);
TituloUI.text = placeInfo.Titulo;
TextoUI.text = placeInfo.Texto;
}
catch
{
Debug.Log("Error in connection");
}
}
}
}
}