Android 用APN來獲取手機號

jopen 11年前發布 | 22K 次閱讀 Android Android開發 移動開發

之前很多人說無法完全獲取手機號,是因為現在有的卡不能獲取,有的卡能獲取,現在我們可以換一種思路來考慮問題,就是用V*N的方式請看代碼


1. [代碼]APNNET.java     

01 /**
02 * 電信APN列表
03 * @author wudongdong
04 *
05 */ 
06 public class APNNET { 
07 public static String CTWAP="ctwap"
08 public static String CTNET="ctnet"
09
10 /**
11 * 電信APN列表
12 * @author wudongdong
13 *
14 */ 
15 public class APNNET { 
16 public static String CTWAP="ctwap"
17 public static String CTNET="ctnet"
18
19 //獲得APN的類型  
20  
21  
22  
23 /**
24 * 獲得APN類型
25 * @author wudongdong
26 *
27 */ 
28    
29 public class ApnUtil { 
30 private static Uri PREFERRED_APN_URI = Uri 
31 .parse("content://telephony/carriers/preferapn"); 
32    
33 /**
34 * get apntype
35 * @param context
36 * @return
37 */ 
38    
39 public static String getApnType(Context context){ 
40 String apntype="nomatch"
41 Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,nullnullnull,null); 
42 c.moveToFirst(); 
43 String user=c.getString(c.getColumnIndex("user")); 
44 if(user.startsWith(APNNET.CTNET)){ 
45 apntype=APNNET.CTNET; 
46 }else if(user.startsWith(APNNET.CTWAP)){ 
47 apntype=APNNET.CTWAP; 
48
49 return apntype; 
50
51
52    
53 /**
54 * 獲得APN類型
55 * @author wudongdong
56 *
57 */ 
58 public class ApnUtil { 
59 private static Uri PREFERRED_APN_URI = Uri 
60 .parse("content://telephony/carriers/preferapn"); 
61    
62    
63 /**
64 * get apntype
65 * @param context
66 * @return
67 */ 
68    
69 public static String getApnType(Context context){ 
70 String apntype="nomatch"
71 Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,nullnullnull,null); 
72 c.moveToFirst(); 
73 String user=c.getString(c.getColumnIndex("user")); 
74 if(user.startsWith(APNNET.CTNET)){ 
75 apntype=APNNET.CTNET; 
76 }else if(user.startsWith(APNNET.CTWAP)){ 
77 apntype=APNNET.CTWAP; 
78
79 return apntype; 
80
81 }

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