1

Im facing a big problem, Im trying to connect to an URL using a GET method. It give me an error java.net.UnknownHostException: Unable to resolve host "URL": No address associated with hostname.

I have been reading some post and all people say it is about permissions.My permissions are:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

I can access to that URL by using chrome in my mobile, it means that wifi is working.

I am using a Motorola g 2, API 23.

1
  • I will say debug and check your url again. Commented Jun 2, 2016 at 5:18

2 Answers 2

0
  1. Printing the response on the Log ?

  2. Did you try switching of the WiFi or phone or both and tried again ?

  3. This problem can occur when you are on VPN. I had a similar issue. After disconnecting from the VPN I tried connecting again. It got connected.

  4. Also try rechecking the URL since the UnknownHostException is popping up there is high possibility that the URL string you are passing in the program(URL class probably) is wrong.

Hope it helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Log: 06-02 10:30:50.834 10390-10896/com.appcontactos.javierdiaz.jeunessemiami W/System.err: java.net.UnknownHostException: Unable to resolve host "dashboard.jeunesse.net": No address associated with hostname
I reset Wifi and phone several times, I'm not connected to any VPN. When I get the url and paste it in google chrome it got connected.
0

You have two solutions for your problem. The quick one is to lower targetApi to 22 (build.gradle file). Second is to use the new runtimePermission model: Since your target api is 23 you should add the permissions on runtime too.

if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
        != PackageManager.INTERNET) {

    // Should we show an explanation?
    if (shouldShowRequestPermissionRationale(
            Manifest.permission.INTERNET)) {
        // Explain to the user why we need to read the contacts
    }

    requestPermissions(new String[]{Manifest.permission.INTERNET},
            MY_PERMISSIONS_REQUEST_INTERNET);

    // MY_PERMISSIONS_REQUEST_INTERNET is an
    // app-defined int constant

    return;
}

Sniplet found here: https://developer.android.com/preview/features/runtime-permissions.html

1 Comment

Yes, I started using volley and it works. Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.