I have an event on a Button which makes a HttpURLConnection in order to access an API Service which is on my local server to retrieve a JSON. When I click the Button it gives me :
"D/NetworkSecurityConfig: No Network Security Config specified, using platform default"
But then when I press again the Button it gives me the JSON string. So my question is : how do I make it to give me the JSON the first time I press the Button without pressing it 2 times.
This is the code
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setDoInput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
json = reader.readLine();
return json;