Android 用APN来获取手机号
之前很多人说无法完全获取手机号,是因为现在有的卡不能获取,有的卡能获取,现在我们可以换一种思路来考虑问题,就是用V*N的方式请看代码
1. [代码]APNNET.java
07 | public static String CTWAP="ctwap"; |
08 | public static String CTNET="ctnet"; |
16 | public static String CTWAP="ctwap"; |
17 | public static String CTNET="ctnet"; |
29 | public class ApnUtil { |
30 | private static Uri PREFERRED_APN_URI = Uri |
31 | .parse("content://telephony/carriers/preferapn"); |
39 | public static String getApnType(Context context){ |
40 | String apntype="nomatch"; |
41 | Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null,null); |
43 | String user=c.getString(c.getColumnIndex("user")); |
44 | if(user.startsWith(APNNET.CTNET)){ |
46 | }else if(user.startsWith(APNNET.CTWAP)){ |
58 | public class ApnUtil { |
59 | private static Uri PREFERRED_APN_URI = Uri |
60 | .parse("content://telephony/carriers/preferapn"); |
69 | public static String getApnType(Context context){ |
70 | String apntype="nomatch"; |
71 | Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null,null); |
73 | String user=c.getString(c.getColumnIndex("user")); |
74 | if(user.startsWith(APNNET.CTNET)){ |
76 | }else if(user.startsWith(APNNET.CTWAP)){ |
</div> </div> </div>
2. [代码][Java]代码
02 | 获得手机号码的话可以传IMSI码到指定接口,接口地址不方便说。但可以透露一点,必须走CTWAP,这也是判断APN类型的原因,发现很多应用如果APN是走代理的话就不能联网,那么再介绍一下用APN设置网络的代理信息。 |
05 | Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null,null); |
07 | String proxy=c.getString(c.getColumnIndex("proxy")); |
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 " |