android获取当前接入点信息判断是ctwap还是ctnet实例代码
程序员文章站
2022-07-11 19:30:35
复制代码 代码如下:/** * 获取当前的接入点是ctwap还是ctnet * @aut...
复制代码 代码如下:
/**
* 获取当前的接入点是ctwap还是ctnet
* @author <a href="mailto:yejiurui@126.com">yejiurui</a>
* @version 1.0 2013-5-17 下午5:46:05 2013
*/
private string ctwap="ctwap";
private string ctnet="ctnet";
private uri preferred_apn_uri = uri
.parse("content://telephony/carriers/preferapn");
public string getapntype(context context) {
string apntype = "nomatch";
cursor c = context.getcontentresolver().query(preferred_apn_uri, null,
null, null, null);
c.movetofirst();
string user = c.getstring(c.getcolumnindex("apn"));
if (user.startswith(ctnet)) {
apntype = ctnet;
} else if (user.startswith(ctwap)) {
apntype = ctwap;
}
return apntype;
}