Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConnectivityManager setNetworkPreference() / getNetworkPreference(): How are they actually used?

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!

like image 595
robguinness Avatar asked Mar 03 '26 11:03

robguinness


1 Answers

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.

like image 165
wojciii Avatar answered Mar 05 '26 00:03

wojciii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!