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;
}
//需要添加一些权限:
android cmwap 切换 cmnet,Android上关于cmwap/cmnet网络切换的疑惑?相关推荐
- Android上关于cmwap/cmnet网络切换的疑惑?
一.在网上看到一段代码,是检测当前手机网络,并且自动切换到Cmwap网络的demo,理论上是可行的,可以修改到cmwap的但是在实际运行中会报错这样的错误: 二.错误如下: Caused by: ja ...
- android cmwap 切换 cmnet,Android CMWAP和CMNET 切换APN
转自:http://seya.iteye.com/blog/897576 有的中国移动的业务需要走CMWAP接入点才能够连接网络的,在做这类应用的时候,不可避免地需要判断当前APN, 切换APN,以及 ...
- Android 开发:APN网络切换之CMNET
最近被Android系统的APN自动切换网络问题折腾死了,软件使用CMNET网络,而系统自带的一些软件必须使用CMWAP,或者手机厂家搞的一些后台服务或者流氓软件总是在切换网络.没办法,只好想个解决之 ...
- Android开发之APN网络切换
原文:http://www.cnblogs.com/hanyonglu/archive/2012/03/29/2423298.html 本文介绍Android平台中关于APN网络切换的相关知识以及如何 ...
- android如何自定义viewpager,Android自定义ViewPager实现个性化的图片切换效果
第一次见到ViewPager这个控件,瞬间爱不释手,做东西的主界面通通ViewPager,以及图片切换也抛弃了ImageSwitch之类的,开始让ViewPager来做.时间长了,ViewPager的 ...
- android头部固定悬停,Android开发上滑悬停且头部可刷新
需求:上滑列表后推荐,小岛,专题置顶,可左右切换.因为头部有重要内容,所有头部出现且滑到顶之后,再下来可刷新头部内容 效果图: scroll1.jpg Screenshot_20200627_1341 ...
- android 简单的音乐播放器实现播放模式的切换
以前写过一篇简单的音乐播放器,但是这个播放器没有实现播放模式的切换,在项目中要实现两个播放模式,循环播放和随机播放,经过这两天的努力搞定了,界面比较粗糙.可以先看一下前面的简单音乐播放器,详细的就不说 ...
- android app 主界面,android ViewPager实现App主界面Tab菜单页面切换和点击事件
Tabhost实现页面滑动切换比较麻烦,这里介绍一下viewPage 控件. 实现了三屏滑动带标题点击和tab页面内按钮的的点击事件实现: viewPage 的优点是可以滑动切换缺点是MainAct ...
- android 调出键盘表情_Android 软键盘和emoji表情切换方案,和微信几乎一样的体验...
注意:本项目还有一个小坑.第一次进去的时候有时候输入框没有得到焦点,没有弹出软键盘,所以不能更好的量取软键盘高度,给了一个默认值787 软键盘默认高度.所以可以忽略不计,一旦弹出了软键盘,这个高度就被 ...
- android tab 切换动画,Android之ViewPager+TabLayout组合实现导航条切换效果(微信和QQ底部多标签切换)...
前言 之前在另外一篇中用Fragment和button实现了点击切换Fragment的效果,比较简陋.这次改用ViewPager+TabLayout 实现联动的效果. 实现效果 ViewPager 多 ...
最新文章
- 使用maven创建项目和cannot change version web module 3.0
- 传送门(portal)
- XHTML Strict和Transitional 的区别
- P1121 环状最大两段子段和
- IDEA 中 30 秒生成 Spring Cloud Alibaba 工程
- Raevo最近疯狂迷上了WP
- MySQL数据库的用户授权_查看权限
- ECMAScript 6 学习资料
- ExtJs 入门 [窗体:Window组件]
- DXBC2HLSL Tool
- PLC系统调试的步骤
- 关于openlaeyrs获取谷歌卫星地图的无偏瓦片
- 阿里云,AWS和DigitalOcean:云服务比较
- mysql单表历史记录_Mysql之单表记录查询
- 点击word页面自动弹出信息检索
- Vant Weapp组件picker选择器初始默认选中
- Cloudera简介和安装部署概述
- 教你如何查看linux版本
- 贾跃亭回应传闻:乐视的成功不是靠政府关系
- win10家庭版远程桌面控制解决