Android实现编程修改手机静态IP的方法
本文实例讲述了Android实现编程修改手机静态IP的方法。分享给大家供大家参考。具体如下:
这里演示通过编程方式动态修改手机静态IP的方法,可以用于wifi接入点切换
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolvercr=this.getContentResolver();
try{
if(Settings.System.getInt(cr,Settings.System.WIFI_USE_STATIC_IP)==0){
Log.d("Demo","NouseStaticIP!");
}
else{
Log.d("Demo","useStaticIPandChangeIPto192.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(SettingNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
希望本文所述对大家的Android程序设计有所帮助。