android cmwap 切换 cmnet,Android上关于cmwap/cmnet网络切换的疑惑?

//获取当前APN属性

private booleangetCurrentAPN(){

PREFERRED_APN_URI= Uri.parse("content://telephony/carriers/preferapn");

cursor_current= this.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);if(cursor_current != null &&cursor_current.moveToFirst()){

String proxy= cursor_current.getString(cursor_current.getColumnIndex("proxy"));

String apn= cursor_current.getString(cursor_current.getColumnIndex("apn"));

String port= cursor_current.getString(cursor_current.getColumnIndex("port"));

String current= cursor_current.getString(cursor_current.getColumnIndex("current"));if(proxy == null || apn == null || port == null || current == null

|| proxy.equals("") || port.equals("")){return false;

}if((proxy.equals("10.0.0.172") || proxy.equals("010.000.000.172")) && port.equals("80") &&apn.equals("cmwap") && current.equals("1")){return true;

}

}return false;

}//检查是否存在cmwap网络

private booleancheckHasWapAPN(){

APN_TABLE_URI= Uri.parse("content://telephony/carriers");

cursor_need= this.getContentResolver().query(APN_TABLE_URI, null, null, null, null);while(cursor_need != null &&cursor_need.moveToNext()){

String id= cursor_need.getString(cursor_need.getColumnIndex("_id"));

String port= cursor_need.getString(cursor_need.getColumnIndex("port"));

String proxy= cursor_need.getString(cursor_need.getColumnIndex("proxy"));

String current= cursor_need.getString(cursor_need.getColumnIndex("current"));

String mmsc= cursor_need.getString(cursor_need.getColumnIndex("mmsc"));if(proxy == null || port == null || current == null){continue;

}if((proxy.equals("10.0.0.172") || proxy.equals("010.000.000.172"))&& port.equals("80") && current.equals("1")&& mmsc == null){

APN_Id=id;return true;

}

}return false;

}//设置为cmwap网络

public boolean setAPN(intid){//如果wifi是打开的,则关闭

wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);if(wifi.isWifiEnabled()){

wifi.setWifiEnabled(false);

}boolean res = false;

ContentResolver resolver= this.getContentResolver();

ContentValues values= newContentValues();

values.put("apn_id", id);try{

resolver.update(PREFERRED_APN_URI, values,null, null);

Cursor c= resolver.query(PREFERRED_APN_URI, new String[]{"name", "apn"}, "_id=" + id, null, null);if(c != null){

res= true;

c.close();

}

}catch(SQLException e){

Log.e("lhl", e.getMessage());

}returnres;

}//添加cmwap网络

private intaddCmwapAPN(){

ContentResolver cr= this.getContentResolver();

ContentValues cv= newContentValues();

cv.put("name", "cmwap");

cv.put("apn", "cmwap");

cv.put("proxy", "010.000.000.172");

cv.put("port", "80");

cv.put("current", 1);

tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

String imsi=tm.getSubscriberId();if(imsi != null){if(imsi.startsWith("46000")){

cv.put("numeric", "46000");

cv.put("mcc", "460");

cv.put("mnc", "00");

}else if(imsi.startsWith("46002")){

cv.put("numeric", "46002");

cv.put("mcc", "460");

cv.put("mnc", "02");

}

}

Cursor c= null;try{

Uri newRow=cr.insert(APN_TABLE_URI, cv);if(newRow != null){

c= cr.query(newRow, null, null, null, null);

c.moveToFirst();

String id= c.getString(c.getColumnIndex("_id"));

setAPN(Integer.parseInt(id));returnInteger.parseInt(id);

}

}catch(SQLException e){

Log.e("lhl", e.getMessage());

}finally{if(c != null){

c.close();

}

}return 0;

}

//需要添加一些权限:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值