Android:设置APN为cmnet源码 ----android 4.0之后需要系统签名才能添加

01 publicclassAPNActivityextendsActivity {
02
03 publicstaticfinalUri APN_URI = Uri.parse("content://telephony/carriers");
04 publicstaticfinalUri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
05
06 @Override
07 publicvoidonCreate(Bundle savedInstanceState) {
08 super.onCreate(savedInstanceState);
09 setContentView(R.layout.main);
10 int_cmnetId = addAPN();
11 SetAPN(_cmnetId);
12 }
01 publicvoidcheckAPN(){
02 // 检查当前连接的APN
03 Cursor cr = getContentResolver().query(CURRENT_APN_URI,null,null,
04 null,null);
05 while(cr !=null&& cr.moveToNext()) {
06 // APN id
07 String id = cr.getString(cr.getColumnIndex("_id"));
08 // APN name
09 String apn = StringUtils.null2String(cr
10 .getString(cr.getColumnIndex("apn")));
11 //Toast.makeText(getApplicationContext(),
12 //"当前 id:" + id + " apn:" + apn, Toast.LENGTH_LONG).show();
13
14 }
15
16 //新增一个cmnet接入点
17 publicintaddAPN() {
18 intid = -1;
19 ContentResolver resolver =this.getContentResolver();
20 ContentValues values =newContentValues();
21 values.put("name","cmnet");
22 values.put("apn","cmnet");
23 Cursor c =null;
24 Uri newRow = resolver.insert(APN_URI, values);
25 if(newRow !=null) {
26 c = resolver.query(newRow,null,null,null,null);
27 intidIndex = c.getColumnIndex("_id");
28 c.moveToFirst();
29 id = c.getShort(idIndex);
30 }
31 if(c !=null)
32 c.close();
33 returnid;
34 }
35 //设置接入点
36 publicvoidSetAPN(intid) {
37 ContentResolver resolver =this.getContentResolver();
38 ContentValues values =newContentValues();
39 values.put("apn_id", id);
40 resolver.update(CURRENT_APN_URI, values,null,null);
41 }
42 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值