BindProcessToNetwork not working on a specific device

微笑、不失礼 提交于 2021-01-28 05:07:13

问题


I have an app that's custom built for a client and not available in the Play Store that basically makes some network calls when it detects that the device is connected to their WiFi. This should happen even if it has no internet connection, every request that the app makes is to a local address.
The problem comes with the new batch of tablets that the client has purchased (Galaxy Tab Active 2, Android 8.1.0, Build number M1AJQ.T395XXU3BRJ5), which will always prefer a connection with internet access over whatever network I'm telling it to bind to.
WiFi -> Advanced -> Switch to mobile data is already disabled, so that should not be it.

Here's the code I'm using that has been working until now:

ConnectivityManager cm = (ConnectivityManager) getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = cm.getAllNetworks();
for (int i = 0, networksLength = networks.length; !bound && i < networksLength; i++) {
    Network network = networks[i];
    if (correctNetwork(network)) { //SSID check
        bound = cm.bindProcessToNetwork(network);
        Log.i(TAG, "Bound? " + bound);
    }
}

On all their previous devices, my own phone and even a Galaxy Tab Active 1 this is working: we see "Bound? true" in the logs and every connection is made through the right network. On the Active 2 we always see "Bound? false" and it will use the 4G connection. Disabling data is not an option.

If this is a Samsung bug, is there a workaround for it? Or maybe an alternative way of forcing an HttpURLConnection to use a specific network?

来源:https://stackoverflow.com/questions/55178150/bindprocesstonetwork-not-working-on-a-specific-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!