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 }

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 《MySQL技术内幕——SQL编程》读书笔记(
  2. mysql 大数据量高效分页查询
  3. jQuery执行PHP MySQL查询
  4. Wordpress数据库类- MySQL类型。
  5. Server 2016 部署Nginx,PHP遇到的一些问
  6. XMPP环境搭建 (mac环境下 安装自己独立的
  7. MySql数据库安装
  8. Eclipse + hibernate tools + xdoclet +
  9. Mysql循环选择列并在循环中执行Insert查
  10. MySql 表管理常用的sql语句