2G-3G handover for android network types

Posted by unrelenting on Fri, 05 Jul 2019 03:00:41 +0200

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
  1. 7 = Global  
  2. 6 = EvDo only  
  3. 5 = CDMA w/o EvDo  
  4. 4 = CDMA / EvDo auto  
  5. 3 = GSM / WCDMA auto  
  6. 2 = WCDMA only  
  7. 1 = GSM only  
  8. 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
  1. 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.
  1. 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 ____________
  1. settings put global airplane_mode_on 1  
  2. am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true  
  3.   
  4. settings put global airplane_mode_on 0  
  5. 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.
  1.   /** 
  2.     * Setting up network mode
  3.     * @param context 
  4.     * @param mode 
  5.     */  
  6. public void setPreferedNetworkType(Context context, int mode){  
  7.     //<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>  
  8.     Settings.Secure.putInt(context.getContentResolver(), "preferred_network_mode", mode);  
  9.     // change mode  
  10.     Intent intent = new Intent("com.android.phone.CHANGE_NETWORK_MODE");  
  11.     intent.putExtra("com.android.phone.NEW_NETWORK_MODE", mode);  
  12.     context.sendBroadcast(intent);  
  13. }  
  14.   
  15.   
  16. /** 
  17.     * Get the current network mode
  18.     * @param context 
  19.     * @return 
  20.     * @throws SettingNotFoundException  
  21.     */  
  22.    public int getPreferedNetworkType(Context context) throws SettingNotFoundException {  
  23.     return Settings.Secure.getInt(context.getContentResolver(), "preferred_network_mode");  
  24.     }  
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.
  1. http://www.clearevo.com/blog/howto/2012/10/10/android_force_wcdma_or_gsm_or_auto_from_shell.html  
  2.   
  3. http://forum.xda-developers.com/showthread.php?t=2230207  

 

To: http://hmxingkong.ddjava.com/blog/blog.html?blogId=662

 

Reprinted at: https://www.cnblogs.com/sunfb/p/3941967.html

Topics: Android network Mobile Database