In android mobile phone'Settings'-'Mobile Network Type', you can see the options about network type, generally default to 3G priority.
If you need to switch the network type of friends in the program, you might as well try the following methods. Several ideas are provided here, although they may be addressed.
Mobile phones are not very friendly.
0)NetworkMode
From Android source code, The preferred network mode
- 7 = Global
- 6 = EvDo only
- 5 = CDMA w/o EvDo
- 4 = CDMA / EvDo auto
- 3 = GSM / WCDMA auto
- 2 = WCDMA only
- 1 = GSM only
- 0 = GSM / WCDMA preferred
1)HardCode
You can use Intent to wake up the set network type selection interface, first get the coordinates of the specified options, through which you can combine sendevent or ___________
monkey implements click-to-click switching. As for how to arouse the interface, there is an attempt to give no code, for coordinate clicks, you can combine my own.
The previous article on android testing was implemented.
2)Phone test
Similar to mode 1, the difference is that you need to enter *#* 4636 ** in the dial-up interface to call up the test interface and enter the cell phone information column.
Find the relevant options, don't say much.
3)Database
Execute database modification statements in the shell and trigger loading after changing values about network types
- sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update secure set value='2' where name='preferred_network_mode'"
Then restart the phone or kill the process com.android.phone directly, if executing kill requires the device to have root privilege.
If the phone has a busybox, it can be executed directly.
- ps|grep -v 'grep '| grep com.android.phone | awk '{FS=" "} {print $2}' | while read s; do kill -9 $s; done
I don't think the success factor of this method is very high, at least try it on my own equipment. One is to modify the global table, which has not been verified.
4)settings
If your system is 4.2 or above, you can use the settings command directly. The following commands are for flight mode settings.
One way to modify the ____________
- settings put global airplane_mode_on 1
- am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true
-
- settings put global airplane_mode_on 0
- am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false
5)AirplaneMode
Modify the Secure property of the system by imitating the way of setting flight mode, and code directly.
-
- public void setPreferedNetworkType(Context context, int mode){
-
- Settings.Secure.putInt(context.getContentResolver(), "preferred_network_mode", mode);
-
- Intent intent = new Intent("com.android.phone.CHANGE_NETWORK_MODE");
- intent.putExtra("com.android.phone.NEW_NETWORK_MODE", mode);
- context.sendBroadcast(intent);
- }
-
-
- public int getPreferedNetworkType(Context context) throws SettingNotFoundException {
- return Settings.Secure.getInt(context.getContentResolver(), "preferred_network_mode");
- }
This is very straightforward, you can see the effect immediately, the only drawback is that your apk must have system privileges, to
I haven't verified the system before 2.3.
It should be pointed out that methods 3, 4 and 5 are not my original works, but the works of foreign cattle people, in order to make up for the lack of domestic information.