public static String getJsonSystem(String urlString){
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
String retorno = "";
try{
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
StringBuffer buffer = new StringBuffer();
while ((line = reader.readLine()) != null){
buffer.append(line);
}
retorno = buffer.toString();
} catch (Exception e){
e.printStackTrace();
}
return retorno;
}
Aqui como eu chamo a conexão:
String caminho = "http://192.168.0.11/system/pages/login";
HttpConnection conexão = new HttpConnection();
String resp = conexão.getJsonSystem(caminho);
AlertDialog.Builder alerta = new AlertDialog.Builder(this);
alerta.setMessage(resp);
alerta.show();
<uses-permission android:name="android.permission.INTERNET" />