Code example for URI

Methods: toASCIIString

0
 
    @Override 
    public WeatherObservation getWeather(double latitude, double longitude) {
        try { 
            String query = "lat=" + latitude + "&lon=" + longitude + "&cnt=1";
            URI uri = new URI("http", "api.openweathermap.org", "/data/2.1/find/city", query, null);
            URL url = new URL(uri.toASCIIString());
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            try { 
                if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    InputStream in = new BufferedInputStream(conn.getInputStream());
                    return readStream(in);
                } 
            } finally { 
                conn.disconnect();
            } 
        } catch (URISyntaxException e) {
            Log.wtf(TAG, "Invalid URI", e);
        } catch (MalformedURLException e) {
            Log.wtf(TAG, "Invalid URL", e);
        } catch (IOException e) {