0

I am using Volley library to get JSON object from API, but it is not working in application but it is working when I open the same URL using Intent, Video - https://youtu.be/FVLxZex4d1Q, any idea what could be happening?

my function -

private void setAQI(String lat, String lon)
    {
        lat = "19.225605576461163";
        lon = "72.9011831141636";
        RequestQueue aqiQueue;
        aqiQueue = Volley.newRequestQueue(MainActivity.this);

        String aqi_api_key = "49e64a55-033c-42d3-bb37-cbe436c78682";
        String aqiURL = "http://api.airvisual.com/v2/nearest_city?lat=" + lat + "&lon=" + lon + "&key=" + aqi_api_key;

        JsonObjectRequest request = new JsonObjectRequest
                (Request.Method.GET, aqiURL, null, response -> {

                    String responseMessage = "Successful call";
                    Toast.makeText(MainActivity.this, responseMessage, Toast.LENGTH_LONG).show();

                }, error -> {
                    String responseMessage = "Something went wrong in JsonObjectRequest, line 239";
                    Toast.makeText(MainActivity.this, responseMessage, Toast.LENGTH_LONG).show();
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(aqiURL));
                    startActivity(browserIntent);
                });
        aqiQueue.add(request);
    }
Aman Jain
  • 13
  • 3

0 Answers0