Android Force App To Use Mobile Data Channel
I am doing some investigation on an app I am developing. The issue is the app requires connection to mobile data network so when wifi is on, it will not route properly since the s
Solution 1:
You can't explicitly force the communications channel on a per-app basis (you can request to use a preferred mode via ConnectivityManager.setNetworkPreference(...)
, but that's not "forcing").
Though it's probably terrible UX, you can inform the user that your app disallows use of WiFi, then disable their WiFi if they want to continue. To do so, you need the ACCESS_WIFI_STATE
and CHANGE_WIFI_STATE
permissions. The code would look something like this:
manager = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
if(manager.isWifiEnabled()) {
manager.setWifiEnabled(false);
}
// and to be sure:
ConnectivityManager.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
Post a Comment for "Android Force App To Use Mobile Data Channel"