0

I have an App about driving record device.

Operate by connecting device WiFi.(IP like:192.72.3.1).

*My WiFi no Internet.

But when I turn on 3g/4g.

The app will use 3g / 4g IP sendRequest to the device.(IP like:10.200.172.xxx).

How I specify an app to use WiFi when the phone is connected to several networks?

Error Log: System.err: java.net.SocketTimeoutException: failed to connect to /192.72.3.1 (port 80) from /10.200.172.xxx (port 41776) after 3000ms

compileSdkVersion 23

buildToolsVersion "28.0.3"

defaultConfig {
    applicationId "my.app"
    minSdkVersion 14
    targetSdkVersion 18
}

This code does not work for me:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            for (Network net : connectivityManager.getAllNetworks()) {
                NetworkInfo networkInfo = connectivityManager.getNetworkInfo(net);
                if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    connectivityManager.bindProcessToNetwork(net);
                    break;
                }
            }
        }

0 Answers0