0

With this code

  URL url = new URL(data.replaceAll(" ", "%20"));
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setReadTimeout(12000);
        urlConnection.setConnectTimeout(12000);
        int xy = urlConnection.getResponseCode();

I'm getting this exception:

data = "http://myrpd.us/api/staff1?lang=eng"
urlConnection = {HttpURLConnectionImpl@11410}    "com.android.okhttp.internal.huc.HttpURLConnectionImpl:http://myrpd.us/api/staff1?lang=eng"
e = {UnknownHostException@11411} "java.net.UnknownHostException: Unable to resolve host "myrpd.us": No address associated with hostname"

The URL works fine on 9 and in a browser. I've read all the privacy information that's new with 10. I have this in the manifest:

android:usesCleartextTraffic="true"
Bob Lissner
  • 255
  • 4
  • 17
  • 1
    Did you try this https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie – Arun Shankar Oct 17 '19 at 03:58

1 Answers1

1

This error may also occur when there is no Internet connection

java.net.UnknownHostException: Unable to resolve host 

Can you check the Internet connection on your Android 10 device?

serkancay
  • 175
  • 1
  • 12
  • This problem is occuring on the emulator/simulator, and my Mac clearly has internet connection. – Bob Lissner Oct 17 '19 at 05:40
  • I have tried your code to be sure. It was worked on my emulator(Nexus 5X API 29 Android 10). Finally, make sure that the emulator's Wi-Fi or mobile data is turned on. That's what I think of. – serkancay Oct 17 '19 at 05:48
  • 1
    This is the correct answer. I've never before seen an emulator start without wifi automatically running through Android Studio. I thought the problem was somehow related to 10's Privacy features. Thank you serkancay. – Bob Lissner Oct 17 '19 at 06:22