- Home /
Downloading data from MySql database not working on Android.
I have a very weird problem. I have an application which is supposed to get an image url and some text from a database on a server. It works perfectly on a computer but when I build it to Android it doesn't load the image nor the text. What's weirder is that my friend who is working on the same project did an almost identical script accessing a different database extracting world coordinates to spawn markers on the world map and it works on both Android and PC.
public void callGetInfo() {
StartCoroutine(getInfo(currentButtonText,titletext.text));
StartCoroutine(getInfo(currentButtonText,"picture"));
}
public IEnumerator getInfo(string name, string data) {
//print (data);
string newURL = "grainr.net/get_cult_info.php?name=" + name.ToLower() + "&requested_data=" + data.ToLower();
//string imgURL ="grainr.net/get_cult_info.php?name=" + name.ToLower() + "&requested_data=picture";
//string imgURL = "http://www.themonitordaily.com/wp-content/uploads/2015/03/aplle.jpg";
WWWForm form = new WWWForm ();
form.AddField ("name", name.ToLower());
form.AddField ("requested_data", data.ToLower());
WWW getData = new WWW(newURL,form);
yield return getData;
if (getData.error != null){
}
else{
}
if(data == "picture")
{
stringReturnImageURL = getData.text;
print(stringReturnImageURL);
StartCoroutine(getPic(stringReturnImageURL));
} else {
texttext.text = getData.text;
}
}
public IEnumerator getPic(string name) {
print (name);
//string imgURL ="grainr.net/get_cult_info.php?name=" + name.ToLower() + "&requested_data=picture";
//string imgURL = "http://www.themonitordaily.com/wp-content/uploads/2015/03/aplle.jpg";
WWW getPic = new WWW(name);
yield return getPic;
if (getPic.error != null){
}
else{
}
image.GetComponent<Image>().sprite = Sprite.Create(getPic.texture,new Rect(0,0,getPic.texture.width,getPic.texture.height),new Vector2(0.5f,0.5f));
}
This is my code (Not working on any android device)
public IEnumerator GetMarkerData (string where1,string where2, string data) {
string login_URL = "http://grainr.net/get_marker_info.php?where_1=" + where1 + "&where_2=" + where2 + "&requested_data=" + data;
WWWForm form = new WWWForm ();
form.AddField ("where_1", where1);
form.AddField ("where_2", where2);
form.AddField ("requested_data", data);
WWW loginReader = new WWW (login_URL,form);
yield return loginReader;
if (loginReader.error != null) {
} else {
}
if (data == "longtitude") {
stringReturnLongtitude = loginReader.text;
}else if (data == "latitude") {
stringReturnLatitude = loginReader.text;
}else if (data == "username") {
stringReturnUsername = loginReader.text;
}else if (data == "id") {
stringReturnId = loginReader.text;
}else if (data == "count") {
stringReturnCount = loginReader.text;
}
coroutineHasFinished = true;
}
My friend's code(working on android/pc)
I need help ASAP. Thanks in advance.
have you completed ? i am stuck on the same problem .. not working on android
Answer by mole1984 · May 16, 2016 at 05:16 PM
It's not working because of url. I think it is because of "http://" . It is important to set it at the right position. watch my source/code on www.appymole.com/downloads - There it is correct and works for Android. I took It from the same wiki and have fixed it
Try it this way:
delete http in your url:
string login_URL = "www.grainr.net/get_marker_info.php?where_1="
Put it in here:
WWW loginReader = new WWW ("http://"+login_URL,form);
Both "http://abc.def" and "http://" + "abc.def" result in exactly the same string. Unless the login_URL
variable is used somewhere that requires the http to not be there then your proposed code change is meaningless.
Your answer
Follow this Question
Related Questions
Should I load all the database items on my android device? 1 Answer
Login from database in unity 0 Answers
Multiple Cars not working 1 Answer
Not allowed to connect to my database. 1 Answer
WWW Form C# on Android 0 Answers