app/src/main/java/net/sky/scweather/sync/WeatherSyncAdapter.java
private String downloadWeatherJson(String paramDate, Integer cityId) {
        String jsonStr = null;
        // example http://ciram.epagri.sc.gov.br/wsprev/resources/listaJson/prevMuni?cdCidade=4205407&data=2017/01/08
        Uri builtUri = Uri.parse(BASE_URL).buildUpon()
                .appendQueryParameter(PARAM_CITY_CODE, cityId.toString())
                .appendQueryParameter(PARAM_DATE, paramDate)
                .build();
        HttpURLConnection urlConnection = null;
        BufferedReader reader = null;
        try {
            URL url = new URL(builtUri.toString());
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();
            InputStream inputStream = urlConnection.getInputStream();
            if (inputStream == null) {
                return null;
            }
            reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder buffer = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
            if (buffer.length() == 0) {
                return null;
            }
            jsonStr = buffer.toString();
        } catch (final IOException e) {
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
        } finally {
            if (urlConnection != null) urlConnection.disconnect();
            if (reader != null) {
                try {
                    reader.close();
                } catch (final IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return jsonStr;
    }
/**
     * Download weather forecast JSON string for a given city and date
     *
     * @param paramDate value of URL parameter 'cdCidade'
     * @param cityId value of URL parameter 'data'
     * @return JSON string or null in case of error
     */
Download weather forecast JSON string for a given city and date

@param paramDate value of URL parameter 'cdCidade'
@param cityId value of URL parameter 'data'
@return JSON string or null in case of error
Download weather forecast JSON string for a given city and date @param paramDate value of URL parameter ' cdCidade ' @param cityId value of URL parameter ' data ' @return JSON string or null in case of error
private String downloadWeatherJson(String paramDate, Integer cityId) {
        String jsonStr = null;
        Uri builtUri = Uri.parse(BASE_URL).buildUpon()
                .appendQueryParameter(PARAM_CITY_CODE, cityId.toString())
                .appendQueryParameter(PARAM_DATE, paramDate)
                .build();
        HttpURLConnection urlConnection = null;
        BufferedReader reader = null;
        try {
            URL url = new URL(builtUri.toString());
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();
            InputStream inputStream = urlConnection.getInputStream();
            if (inputStream == null) {
                return null;
            }
            reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder buffer = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
            if (buffer.length() == 0) {
                return null;
            }
            jsonStr = buffer.toString();
        } catch (final IOException e) {
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
        } finally {
            if (urlConnection != null) urlConnection.disconnect();
            if (reader != null) {
                try {
                    reader.close();
                } catch (final IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return jsonStr;
    }
private String downloadWeatherJson ( String paramDate , Integer cityId ) { String jsonStr = null ; Uri builtUri = Uri . parse ( BASE_URL ) . buildUpon ( ) . appendQueryParameter ( PARAM_CITY_CODE , cityId . toString ( ) ) . appendQueryParameter ( PARAM_DATE , paramDate ) . build ( ) ; HttpURLConnection urlConnection = null ; BufferedReader reader = null ; try { URL url = new URL ( builtUri . toString ( ) ) ; urlConnection = ( HttpURLConnection ) url . openConnection ( ) ; urlConnection . setRequestMethod ( "GET" ) ; urlConnection . connect ( ) ; InputStream inputStream = urlConnection . getInputStream ( ) ; if ( inputStream == null ) { return null ; } reader = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; StringBuilder buffer = new StringBuilder ( ) ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { buffer . append ( line ) ; } if ( buffer . length ( ) == 0 ) { return null ; } jsonStr = buffer . toString ( ) ; } catch ( final IOException e ) { Log . e ( TAG , e . getMessage ( ) ) ; e . printStackTrace ( ) ; } finally { if ( urlConnection != null ) urlConnection . disconnect ( ) ; if ( reader != null ) { try { reader . close ( ) ; } catch ( final IOException e ) { e . printStackTrace ( ) ; } } } return jsonStr ; }
Download weather forecast JSON string for a given city and date
Download weather forecast JSON string for a given city and date
// example http://ciram.epagri.sc.gov.br/wsprev/resources/listaJson/prevMuni?cdCidade=4205407&data=2017/01/08
