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)){ |
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 " |
本文由用戶
jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!