app/src/main/java/com/example/bs206/retrofittest/java/a/MapsActivity.java
/**
     * A method to download json data from url
     */
A method to download json data from url
A method to download json data from url
private String downloadUrl(String strUrl) throws IOException
    {
        String data = "";
        InputStream iStream = null;
        HttpURLConnection urlConnection = null;
        try
        {
            URL url = new URL(strUrl);
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.connect();
            iStream = urlConnection.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
            StringBuffer sb = new StringBuffer();
            String line = "";
            while ((line = br.readLine()) != null)
            {
                sb.append(line);
            }
            data = sb.toString();
            Log.d("downloadUrl", data.toString());
            br.close();
        } catch (Exception e)
        {
            Log.d("Exception", e.toString());
        }
        finally
        {
            iStream.close();
            urlConnection.disconnect();
        }
        return data;
    }
private String downloadUrl ( String strUrl ) throws IOException { String data = "" ; InputStream iStream = null ; HttpURLConnection urlConnection = null ; try { URL url = new URL ( strUrl ) ; urlConnection = ( HttpURLConnection ) url . openConnection ( ) ; urlConnection . connect ( ) ; iStream = urlConnection . getInputStream ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( iStream ) ) ; StringBuffer sb = new StringBuffer ( ) ; String line = "" ; while ( ( line = br . readLine ( ) ) != null ) { sb . append ( line ) ; } data = sb . toString ( ) ; Log . d ( "downloadUrl" , data . toString ( ) ) ; br . close ( ) ; } catch ( Exception e ) { Log . d ( "Exception" , e . toString ( ) ) ; } finally { iStream . close ( ) ; urlConnection . disconnect ( ) ; } return data ; }
A method to download json data from url
A method to download json data from url
// Creating an http connection to communicate with url // Connecting to url // Reading data from url