0

When API call from background service and mobile screen is off. Got the following error.

java.net.UnknownHostException: Unable to resolve host: No address associated with hostname W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:424) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) at java.net.InetAddress.getAllByName(InetAddress.java:214) at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)

 When API call from background service and mobile screen is off. Got the following error.
java.net.UnknownHostException: Unable to resolve host "": No address associated with hostname
W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
                  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
                  at java.net.InetAddress.getAllByName(InetAddress.java:214)
                  at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
                  at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
                  at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
                  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
                  at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
                  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
                  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
                  at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
                  at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)
1
  • 2
    post your code also.. Commented Oct 3, 2018 at 14:23

1 Answer 1

0

If you haven't already done so, add the permissions to your AndroidManifest.xml file.

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

I think that's the most common cause of this UnknownHostException error message. Another possible cause is that your Internet connection is actually down.

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

2 Comments

It's work fine but when i call api in service then after some time i get this error. Again when i resume the app from background it's working fine in service.
I think,when app is in background and then internet connection lost then api call is not working. Suggest me in another way to call api in service when app in background,

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.