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

发布时间:2016-12-8 0:19:21 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Android:设置APN为cmnet源码 ----android 4.0之后需要系统签名才能添加",主要涉及到Android:设置APN为cmnet源码 ----android 4.0之后需要系统签名才能添加方面的内容,对于Android:设置APN为cmnet源码 ----android 4.0之后需要系统签名才能添加感兴趣的同学可以参考一下。

01 public class APNActivity extends Activity { 02   03         public static final Uri APN_URI = Uri.parse("content://telephony/carriers"); 04         public static final Uri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/preferapn"); 05   06         @Override 07         public void onCreate(Bundle savedInstanceState) { 08                 super.onCreate(savedInstanceState); 09                 setContentView(R.layout.main); 10                 int _cmnetId = addAPN(); 11                 SetAPN(_cmnetId); 12         } 01        public void checkAPN(){ 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         public int addAPN() { 18                 int id = -1; 19                 ContentResolver resolver = this.getContentResolver(); 20                 ContentValues values = new ContentValues(); 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                         int idIndex = c.getColumnIndex("_id"); 28                         c.moveToFirst(); 29                         id = c.getShort(idIndex); 30                 } 31                 if (c != null) 32                         c.close(); 33                 return id; 34         } 35         //设置接入点 36         public void SetAPN(int id) { 37                 ContentResolver resolver = this.getContentResolver(); 38                 ContentValues values = new ContentValues(); 39                 values.put("apn_id", id); 40                 resolver.update(CURRENT_APN_URI, values, null, null); 41         } 42 }

上一篇:虚拟主机中对PHP的特殊设置
下一篇:maven常用命令

相关文章

相关评论