首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android 用APN回获取手机号

2013-09-08 
Android 用APN来获取手机号之前很多人说无法完全获取手机号,是因为现在有的卡不能获取,有的卡能获取,现在

Android 用APN来获取手机号

之前很多人说无法完全获取手机号,是因为现在有的卡不能获取,有的卡能获取,现在我们可以换一种思路来考虑问题,就是用VPN的方式请看代码


1. [代码]APNNET.java     01/**02* 电信APN列表03* @author wudongdong04*05*/ 06public class APNNET { 07public static String CTWAP="ctwap"08public static String CTNET="ctnet"0910/**11* 电信APN列表12* @author wudongdong13*14*/ 15public class APNNET { 16public static String CTWAP="ctwap"17public static String CTNET="ctnet"1819//获得APN的类型  20 21 22 23/**24* 获得APN类型25* @author wudongdong26*27*/ 28   29public class ApnUtil { 30private static Uri PREFERRED_APN_URI = Uri 31.parse("content://telephony/carriers/preferapn"); 32   33/**34* get apntype35* @param context36* @return37*/ 38   39public static String getApnType(Context context){ 40String apntype="nomatch"41Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,nullnullnull,null); 42c.moveToFirst(); 43String user=c.getString(c.getColumnIndex("user")); 44if(user.startsWith(APNNET.CTNET)){ 45apntype=APNNET.CTNET; 46}else if(user.startsWith(APNNET.CTWAP)){ 47apntype=APNNET.CTWAP; 4849return apntype; 505152   53/**54* 获得APN类型55* @author wudongdong56*57*/ 58public class ApnUtil { 59private static Uri PREFERRED_APN_URI = Uri 60.parse("content://telephony/carriers/preferapn"); 61   62   63/**64* get apntype65* @param context66* @return67*/ 68   69public static String getApnType(Context context){ 70String apntype="nomatch"71Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,nullnullnull,null); 72c.moveToFirst(); 73String user=c.getString(c.getColumnIndex("user")); 74if(user.startsWith(APNNET.CTNET)){ 75apntype=APNNET.CTNET; 76}else if(user.startsWith(APNNET.CTWAP)){ 77apntype=APNNET.CTWAP; 7879return apntype; 8081}

2. [代码][Java]代码     01/**02 获得手机号码的话可以传IMSI码到指定接口,接口地址不方便说。但可以透露一点,必须走CTWAP,这也是判断APN类型的原因,发现很多应用如果APN是走代理的话就不能联网,那么再介绍一下用APN设置网络的代理信息。03 */04 05    Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,nullnullnull,null); 06    c.moveToFirst(); 07    String proxy=c.getString(c.getColumnIndex("proxy")); 08       09       10    if (!"".equals(proxy) && proxy!=null) { 11    Properties prop = System.getProperties(); 12    System.getProperties().put("proxySet""true"); 13    prop.setProperty("http.proxyHost", c.getString(c.getColumnIndex("proxy"))); 14    prop.setProperty("http.proxyPort", c.getString(c.getColumnIndex("port"))); 15    String authentication = c.getString(c.getColumnIndex("user")) 16    ":" + c.getString(c.getColumnIndex("password")); 17    String encodedLogin = Base64.encode(authentication); 18    uc.setRequestProperty("Proxy-Authorization"" BASIC " 19    + encodedLogin); 20    21       22    c.close();举报

热点排行
Bad Request.