I'm trying to understand the details of the ConnectivityManager. I noticed there are methods setNetworkPreference() and getNetworkPreference(), but there are no details in the documentation about how they should be used, except that they accept/return an integer, respectively. There is also a constant called DEFAULT_NETWORK_PREFERENCE, but that doesn't really provide many hints. Any ideas?
Thanks in advance!
You are right there is no documentation. If you grep in the source code for android, you see the following.
user@host:~/android/system/frameworks$ grep -r "setNetworkPreference" *
base/core/java/android/net/IConnectivityManager.aidl: void setNetworkPreference(int pref);
base/core/java/android/net/ConnectivityManager.java: public void setNetworkPreference(int preference) {
base/core/java/android/net/ConnectivityManager.java: mService.setNetworkPreference(preference);
...
base/cmds/svc/src/com/android/commands/svc/WifiCommand.java: connMgr.setNetworkPreference(ConnectivityManager.TYPE_WIFI);
base/cmds/svc/src/com/android/commands/svc/DataCommand.java: connMgr.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
base/services/java/com/android/server/ConnectivityService.java: public void setNetworkPreference(int preference) {
From the above it looks like only TYPE_WIFI and TYPE_MOBILE are used for setting the preferred method of accessing the network.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With