`
473687880
  • 浏览: 484245 次
文章分类
社区版块
存档分类
最新评论

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 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics