欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android基于APN獲取手機(jī)號(hào)的方法

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

本文實(shí)例講述了Android基于APN獲取手機(jī)號(hào)的方法。分享給大家供大家參考。具體如下:

之前很多人說(shuō)無(wú)法完全獲取手機(jī)號(hào),是因?yàn)楝F(xiàn)在有的卡不能獲取,有的卡能獲取,現(xiàn)在我們可以換一種思路來(lái)考慮問(wèn)題,就是用APN的方式。請(qǐng)看代碼:

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代碼如下:

/**
 獲得手機(jī)號(hào)碼的話可以傳IMSI碼到指定接口,接口地址不方便說(shuō)。但可以透露一點(diǎn),必須走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();

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

相關(guān)文章

最新評(píng)論