目前供職於電信,只做電信的業務,故列表中只有電信的APN資訊
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的類型
Java代碼
/**
* 獲得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;
}
}
獲得手機號碼的話可以傳IMSI碼到指定介面,介面地址不方便說。
但可以透露一點,必須走CTWAP,這也是判斷APN類型的原因
發現很多應用如果APN是走代理的話就不能連網,那麼再介紹一下用APN設定網路的代理資訊。
Java代碼
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();