亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android基于APN獲取手機號的方法

 更新時間:2015年07月21日 10:52:46   作者:華宰  
這篇文章主要介紹了Android基于APN獲取手機號的方法,實例分析了Android使用APN獲取手機號的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了Android基于APN獲取手機號的方法。分享給大家供大家參考。具體如下:

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

APNNET.java如下:

/** 
* 電信APN列表 
* @author wudongdong 
* 
*/ 
public class APNNET { 
public static String CTWAP="ctwap"; 
public static String CTNET="ctnet"; 
} 
/** 
* 電信APN列表 
* @author wudongdong 
* 
*/ 
public class APNNET { 
public static String CTWAP="ctwap"; 
public static String CTNET="ctnet"; 
} 
//獲得APN的類型  
/** 
* 獲得APN類型 
* @author wudongdong 
* 
*/ 
public class ApnUtil { 
private static Uri PREFERRED_APN_URI = Uri 
.parse("content://telephony/carriers/preferapn"); 
/** 
* get apntype 
* @param context 
* @return 
*/ 
public static String getApnType(Context context){ 
String apntype="nomatch"; 
Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null, null); 
c.moveToFirst(); 
String user=c.getString(c.getColumnIndex("user")); 
if(user.startsWith(APNNET.CTNET)){ 
apntype=APNNET.CTNET; 
}else if(user.startsWith(APNNET.CTWAP)){ 
apntype=APNNET.CTWAP; 
} 
return apntype; 
} 
} 
/** 
* 獲得APN類型 
* @author wudongdong 
* 
*/ 
public class ApnUtil { 
private static Uri PREFERRED_APN_URI = Uri 
.parse("content://telephony/carriers/preferapn"); 
/** 
* get apntype 
* @param context 
* @return 
*/ 
public static String getApnType(Context context){ 
String apntype="nomatch"; 
Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null, null); 
c.moveToFirst(); 
String user=c.getString(c.getColumnIndex("user")); 
if(user.startsWith(APNNET.CTNET)){ 
apntype=APNNET.CTNET; 
}else if(user.startsWith(APNNET.CTWAP)){ 
apntype=APNNET.CTWAP; 
} 
return apntype; 
} 
}

Java代碼如下:

/**
 獲得手機號碼的話可以傳IMSI碼到指定接口,接口地址不方便說。但可以透露一點,必須走CTWAP,這也是判斷APN類型的原因,發(fā)現(xiàn)很多應(yīng)用如果APN是走代理的話就不能聯(lián)網(wǎng),那么再介紹一下用APN設(shè)置網(wǎng)絡(luò)的代理信息。
 */
  Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null, null); 
  c.moveToFirst(); 
  String proxy=c.getString(c.getColumnIndex("proxy")); 
  if (!"".equals(proxy) && proxy!=null) { 
  Properties prop = System.getProperties(); 
  System.getProperties().put("proxySet", "true"); 
  prop.setProperty("http.proxyHost", c.getString(c.getColumnIndex("proxy"))); 
  prop.setProperty("http.proxyPort", c.getString(c.getColumnIndex("port"))); 
  String authentication = c.getString(c.getColumnIndex("user")) 
  + ":" + c.getString(c.getColumnIndex("password")); 
  String encodedLogin = Base64.encode(authentication); 
  uc.setRequestProperty("Proxy-Authorization", " BASIC " 
  + encodedLogin); 
  } 
  c.close();

希望本文所述對大家的Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論