I've been playing around with Android Studio and trying to establish a connection to a dev environment in which reponds back with JSON. I have tested my code and Eclipse (not ADK) and it works fine. I've added the permissions to the AndroidManifest.xml
file for INTERNET
and ACCESS_NETWORK_STATE
so that has been covered. I dont know what else to do?
My Java:
public class GetClientDetails {
public void jsonResponse () {
try{
URL url = new URL("http://invsydmdev069:7080/IFXJSON?type=PartyRq&RqUID=123456789&PartyId=1093300");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept", "application/json");
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader (is, "UTF-8") );
try {
String preJsonObj = reader.readLine();
JSONObject jsonObj = new JSONObject(preJsonObj);
String strPartyId = jsonObj.getJSONObject("PartyRs").getJSONObject("PartyRec").getString("PartyId");
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
catch(Exception e)
{
System.out.println("its fked");
}
}
}