AVD not able to connect to the internet?

Viewed 1019

I've tried running an app that fetches JSON data from the internet through an HTTP Request object, It showed

java.net.UnknownHostException: Unable to resolve host “api.github.com”: No address associated with hostname

as the Exception for every trial. Later I checked the internet connectivity in the AVD by running a browser. I wasn't able to access any site.

Is there any settings that I'll have to change in the AVD Manager so that I can access the in the Internet through the Virtual Device.

Help me out, Thanks in Advance.

2 Answers

If that is your exact error, I see what's wrong just from that.

Android API's, unlike any modern browser, requires explicit declaration of http or https.

You have to make sure the URL contains either of those protocols which you either can do by adding it into the URL manually, or adding this code before you create the volley request:

if(!url.startsWith("http://") && !url.startsWith("https://")){
    url = "http://" + url;
}

You could replace it with HTTPS, but not all sites have https, so it's a generally good idea to default it to HTTP to not get errors from that. If you supply https but there's no HTTPS certificate, the website will most likely refuse the connection.

Related