I send a HTTP request and receive a JSON. I have the JSON format outlined in a class structure. Linq queries this json and submits the powers (variables) for the next scene.
This works for my Unity editor when I run on PC. However, when I build and run on my Android, it doesn't return any values from the query, even though the HTTP request is successful.
private void SendJson(string currPlayer)
{
string bodyJsonString = "{\"player_id\":\"" + currPlayer + "\"}";
string currURI = djangoApi + userOwnedMarbles;
StartCoroutine(PostRequestCoroutine(currURI, bodyJsonString));
}
private IEnumerator PostRequestCoroutine(string url, string json)
{
var jsonBinary = System.Text.Encoding.UTF8.GetBytes(json);
DownloadHandlerBuffer downloadHandlerBuffer = new DownloadHandlerBuffer();
UploadHandlerRaw uploadHandlerRaw = new UploadHandlerRaw(jsonBinary);
uploadHandlerRaw.contentType = "application/json";
UnityWebRequest www =
new UnityWebRequest(url, "POST", downloadHandlerBuffer, uploadHandlerRaw);
yield return www.SendWebRequest();
if (www.isNetworkError)
Debug.LogError(string.Format("{0}: {1}", www.url, www.error));
else
{
string test = string.Format("{0}", www.downloadHandler.text);
JObject myJson = JObject.Parse(test);
Debug.Log("welcome" + test);
var welcome2 = Welcome.FromJson(www.downloadHandler.text);
CurrPower.numberColorBombs = welcome2.Marbles.Count(n => n.Nickname.ToLower() == "Corkscrew Swirl".ToLower());
CurrPower.myPowerups[0] = CurrPower.numberColorBombs;
CurrPower.numberVerticalBombs = welcome2.Marbles.Count(n => n.Nickname.ToLower() == "Clearie".ToLower());
CurrPower.myPowerups[1] = CurrPower.numberVerticalBombs;
CurrPower.numberHorizontalBombs = welcome2.Marbles.Count(n => n.Nickname.ToLower() == "Cloud".ToLower());
CurrPower.myPowerups[2] = CurrPower.numberHorizontalBombs;
CurrPower.numberAdjacentBombs = welcome2.Marbles.Count(n => n.Nickname.ToLower() == "Onionskin".ToLower());
CurrPower.myPowerups[3] = CurrPower.numberAdjacentBombs;
CurrPower.numberSingleBombs = welcome2.Marbles.Count(n => n.Nickname.ToLower() == "Bullseye".ToLower());
CurrPower.myPowerups[4] = CurrPower.numberSingleBombs;
}
}
Welcome2
contains the partial class that has all the elements of the json object. Does Android not handle LINQ well?
Here the the AndroidLauncherManifest.xml
file that I've edited
<?xml version="1.0" encoding="utf-8"?>
<!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:usesCleartextTraffic="true" tools:ignore="GoogleAppIndexingWarning" android:label="@string/app_name" android:icon="@mipmap/app_icon" />
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</manifest>