question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

okhttp cellular and wifi problem

See original GitHub issue

Hi,

I’ve got problem OkHttpClient. Cellular data on, WIFI connected. Application reqests HTTPS and everything works perfect. When WIFI lose connection (still on) app link through cellular and works ok. The problem is when phone connect back to this WIFI {java.net.UnknownHostException: Unable to resolve host: No address associated with hostname}

The only solution is to restart app, but I try to do this using JobScheduler and it have to work in backgroud.

    var vProtokoly : java.Util.List<Protocol> := new java.util.ArrayList<Protocol>;
    var vUprawnienia : RemObjects.Elements.RTL.String;
    var Wywolanie : Request;
    var Odpowiedz : Response;

    vProtokoly.add(Protocol.HTTP_1_1);
    vUprawnienia := okhttp3.Credentials.basic('some', 'credentials');

    Http := new OkHttpClient.Builder()
		.connectTimeout(15,java.util.concurrent.TimeUnit.SECONDS)
		.writeTimeout(20,java.util.concurrent.TimeUnit.SECONDS)
		.readTimeout(20,java.util.concurrent.TimeUnit.SECONDS)
		.retryOnConnectionFailure(false)
		.protocols(vProtokoly)
		.proxy(Proxy.NO_PROXY)
		//.socketFactory(android.net.Network.getSocketFactory())
		.build();
    Http.ConnectionPool.evictAll;

           Wywolanie :=  new okhttp3.Request.Builder().url(Parametry.Uri).header('Authorization',vUprawnienia).build();
        Odpowiedz := Http.newCall(Wywolanie).execute;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
LHeczkocommented, Jun 6, 2019

After some investigation found the problem

I had

android.net.ConnectivityManager.setProcessDefaultNetwork(currentConnection);

in on lostConnection of registerNetworkCallback. After removing this everything works perfect. Sorry and thank you

0reactions
JohnBuenocommented, Oct 14, 2020

@LHeczko I am running into something similar using OKHttp and Retrofit. It also seems to be specific to a certain kind of device. I don’t know that we have any specific code set up in lostConnection or registerNetworkCallback though. Where would I look for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Force OkHttp Request Over Mobile Network
My app has certain requests that must be sent over the cellular network (3G, LTE, 4G, not Wifi). I'm using Retrofit and OkHttp...
Read more >
Android: Intercept on no internet connection | by Elye - Medium
So in this blog, I'll show how to setup no internet connection detection naturally in OkHttp, which only needs to be done once...
Read more >
How can I fix an issue where multiple okhttp requests fail over ...
I am working on an app that pulls information from an API via JSON format. This one request has never been problematic: When...
Read more >
Overview - OkHttp - Square Open Source
OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses, ...
Read more >
DNS caches bogus entries [36989750] - Issue Tracker - Google
W/System.err( 983): at com.android.okhttp.internal.http.RouteSelector. ... The log shows you got on wifi, connected to cellular data and then
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found