android CMWAP CMNET
android CMWAP CMNET
CMWAP和CMNET是中国移动为其划分的两个GPRS接入方式。
CMWAP
CMWAP接入时只能访问GPRS网络内的IP(10...*)网络, 而无法通过路由访问Internet,
CMWAP浏览Internet是通过WAP网关协议或它提供的HTTP代理服务实现。
CMWAP需要设置代理才能连接Internet,接入方式下正常工作需满足:
1、应用程序的网络请求基于HTTP协议。
2、应用程序支持HTTP代理协议或WAP网关协议。
CMNET
可以用GPRS访问Internet
//———–cmwap———–
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection(proxy);
NetworkInfo方法
getDetailedState():获取详细状态。
getExtraInfo():获取附加信息。
getReason():获取连接失败的原因。
getType():获取网络类型(一般为MOBILE或WIFI)。
getTypeName():获取网络类型名称(一般取值“WIFI”或“MOBILE”)。
isAvailable():判断该网络是否可用。
isConnected():判断是否已经连接。
isConnectedOrConnecting():判断是否已经连接或正在连接。
isFailover():判断是否连接失败。
isRoaming():判断是否漫游
//移动CMNET方式
getExtraInfo 的值是cmnet
//移动CMWAP方式
getExtraInfo 的值是cmwap 需在代理的情况下访问普通的网站)
//联通3gwap方式
getExtraInfo 的值是3gwap
//联通3gnet方式
getExtraInfo 的值是3gnet
//联通uniwap方式
getExtraInfo 的值是uniwap
//联通uninet方式
getExtraInfo 的值是uninet
public static int getAPNType(Context context){ private static final int CMNET=1; private static final int CMWAP=2; private static final int WIFI=3;int netType = -1; ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if(networkInfo==null){ return netType; } int nType = networkInfo.getType(); if(nType==ConnectivityManager.TYPE_MOBILE){ Log.d("getAPNType", "networkInfo.getExtraInfo() = "+networkInfo.getExtraInfo()); if(networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) { netType = CMNET; } else{ netType = CMWAP; } } else if(nType==ConnectivityManager.TYPE_WIFI){ netType = WIFI; } return netType;
} Uri PREFERRED_APN_URI, APN_TABLE_URI;
String APN_Id; //获取当前APN(access point name)属性
private boolean getCurrentAPN(){ PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn"); Cursor 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 boolean checkHasWapAPN(){ APN_TABLE_URI = Uri.parse("content://telephony/carriers"); Cursor 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(int id){ boolean res = false; ContentResolver resolver = this.getContentResolver(); ContentValues values = new ContentValues(); 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){ e.printStackTrace();} return res;
}//添加cmwap网络
private int addCmwapAPN(){ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); cv.put("name", "cmwap"); cv.put("apn", "cmwap"); cv.put("proxy", "010.000.000.172"); cv.put("port", "80"); cv.put("current", 1); TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String imsi =tm.getSubscriberId(); //取出IMSI
/*
getSubscriberId()
Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
getSimSerialNumber()
Returns the serial number of the SIM, if applicable.
getLine1Number()
Returns the phone number string for line 1, for example, the MSISDN for a GSM phone.
getDeviceId()
Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.String imei = tm.getDeviceId(); //取出IMEI
String tel = tm.getLine1Number(); //取出MSISDN,很可能为空
String imei = tm.getSimSerialNumber(); //取出ICCID
String imsi = tm.getSubscriberId(); //取出IMSIIMSI:international mobiles subscriber identity国际移动用户号码标识,GSM必须写在卡内相关文件中;
MSISDN: mobile subscriber ISDN用户号码,这个是我们说的139,136那个号码;
ICCID: ICC identity集成电路卡标识,这个是唯一标识一张卡片物理号码的;
IMEI:international mobile Equipment identity手机唯一标识码;
*/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)); return Integer.parseInt(id); } }catch(SQLException e){ e.printStackTrace();} finally{ if(c != null){ c.close(); } } return 0;
}
android CMWAP CMNET相关推荐
- android CMWAP, CMNET有何区别
什么是CMNET,什么是CMWAP? 答:CMWAP和CMNET只是中国移动为其划分的两个GPRS接入方式.中国移动对CMWAP作了一定的限制,主要表现在CMWAP接入时只能访问GPRS网络内的IP( ...
- 从12月7日起.广东移动不再区分cmwap,cmnet流量!
以前广东移动的流量一直区分cmwap.cmnet.实在黑暗啊.现在终于取消了.cmwap.cmnet不再区分了.全部都算在套餐内.还好一直没有取消当年开通的5元100M.什么时候能取消月租就更好了. ...
- 黑莓GPRS上网套餐包月 300MB流量 不限CMWAP/CMNET
近日很多朋友都在问我,为什么我的GPRS套餐是300MB不限cmwap cmnet的,而且那么便宜才10元一月. 其实我在之前的文章中有提过这个问题,因为采用非常规手段申请移动定制业务-万花筒,所以当 ...
- 移动 电信 联通 APN cmwap cmnet ctwap ctnet 3gwap uniwap 3gnet uninet是...
移动 电信 联通 APN cmwap cmnet ctwap ctnet 3gwap uniwap 3gnet uninet是什么 怎么设置 APN(Access Point Name),即" ...
- 移动 电信 联通 APN cmwap cmnet ctwap ctnet 3gwap uniwap 3gnet uninet
为什么80%的码农都做不了架构师?>>> 移动 电信 联通 APN cmwap cmnet ctwap ctnet 3gwap uniwap 3gnet uninet是什么 怎 ...
- android cmwap 切换 cmnet,Android CMWAP和CMNET 切换APN
转自:http://seya.iteye.com/blog/897576 有的中国移动的业务需要走CMWAP接入点才能够连接网络的,在做这类应用的时候,不可避免地需要判断当前APN, 切换APN,以及 ...
- Android CMWAP和CMNET 切换APN
转自:http://seya.iteye.com/blog/897576 有的中国移动的业务需要走CMWAP接入点才能够连接网络的,在做这类应用的时候,不可避免地需要判断当前APN, 切换APN,以及 ...
- Android上关于cmwap/cmnet网络切换的疑惑?
一.在网上看到一段代码,是检测当前手机网络,并且自动切换到Cmwap网络的demo,理论上是可行的,可以修改到cmwap的但是在实际运行中会报错这样的错误: 二.错误如下: Caused by: ja ...
- android cmwap 切换 cmnet,Android上关于cmwap/cmnet网络切换的疑惑?
//获取当前APN属性 private booleangetCurrentAPN(){ PREFERRED_APN_URI= Uri.parse("content://telephony/c ...
最新文章
- 正则表达式中?=和?:和?!的理解
- 物资管理信息系统5 -- 删除用户界面
- 这本空降京东当当新书榜TOP1的“算法小抄”是什么来头?
- SqLite中的事务
- java商品搜索功能_利用solr实现商品的搜索功能(实例讲解)
- openresty开发系列2--nginx的简单安装,正向、反向代理及常用命令和信号控制介绍...
- centos6 yum mysql_centos6_yum_mysql
- jquery ajax请求 清除缓存
- cam350 不能打开光绘文件_电子设计工程CAM350光绘工艺的一般流程
- HyperLPR车牌识别代码解读
- 傅里叶变换,拉普拉斯变换和小波变换
- java acr122 读取数据_acr122读写器软件下载
- 微信授权流程技术说明
- 新手入门指南 | 教你如何写研报?
- Paddle入门实战系列(二)基于PaddleOCR的体检报告识别
- 添加额外jars包到Hive
- 【Mqtt】基于paho.mqtt.c库的mqtt客户端实现
- 世界杂志排行TOP(1-100)
- Js与Jq实战:第二讲:JavaScript基础
- 连续微小线段速度前瞻规划算法