本文實(shí)例講述了Android實(shí)現(xiàn)編程修改手機(jī)靜態(tài)IP的方法。分享給大家供大家參考。具體如下:
這里演示通過(guò)編程方式動(dòng)態(tài)修改手機(jī)靜態(tài)IP的方法,可以用于wifi接入點(diǎn)切換
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ContentResolver cr = this.getContentResolver(); try { if (Settings.System.getInt(cr, Settings.System.WIFI_USE_STATIC_IP)==0){ Log.d("Demo", "No use Static IP!"); } else{ Log.d("Demo", "use Static IP and Change IP to 192.168.1.123!"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_IP, "192.168.1.125"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_GATEWAY, "192.168.1.1"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_DNS1, "202.103.24.68"); Settings.System.putString(cr, Settings.System.WIFI_STATIC_DNS2, "202.103.0.68"); } } catch (SettingNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }}希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選