Android 用APN来获取手机号
之前很多人说无法完全获取手机号,是因为现在有的卡不能获取,有的卡能获取,现在我们可以换一种思路来考虑问题,就是用VPN的方式请看代码
01/**02* 电信APN列表03* @author wudongdong04*05*/ 06public class APNNET { 07public static String CTWAP="ctwap"; 08public static String CTNET="ctnet"; 09} 10/**11* 电信APN列表12* @author wudongdong13*14*/ 15public class APNNET { 16public static String CTWAP="ctwap"; 17public static String CTNET="ctnet"; 18} 19//获得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,null, null, null,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; 48} 49return apntype; 50} 51} 52 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,null, null, null,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; 78} 79return apntype; 80} 81}01/**02 获得手机号码的话可以传IMSI码到指定接口,接口地址不方便说。但可以透露一点,必须走CTWAP,这也是判断APN类型的原因,发现很多应用如果APN是走代理的话就不能联网,那么再介绍一下用APN设置网络的代理信息。03 */04 05 Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null,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();举报