Android基于APN獲取手機號的方法
本文實例講述了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)很多應用如果APN是走代理的話就不能聯(lián)網(wǎng),那么再介紹一下用APN設置網(wǎng)絡的代理信息。
*/
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程序設計有所幫助。
相關文章
C/C++在Java、Android和Objective-C三大平臺下實現(xiàn)混合編程
本文主要介紹C/C++在Java、Android和Objective-C三大平臺下實現(xiàn)混合編程,這里舉例說明實現(xiàn)不同平臺用C/C++實現(xiàn)編程的方法,有興趣的小伙伴可以參考下2016-08-08
使用AndroidStudio上傳忽略文件至SVN Server的解決辦法
這篇文章主要介紹了使用AndroidStudio上傳忽略文件至SVN Server的解決辦法 的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-06-06
Android實現(xiàn)氣泡布局/彈窗效果 氣泡尖角方向及偏移量可控
這篇文章主要為大家詳細介紹了Android實現(xiàn)氣泡布局/彈窗效果,可控制氣泡尖角方向及偏移量,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
Android SQLite操作之大數(shù)據(jù)處理與同時讀寫方法
這篇文章主要介紹了Android SQLite操作之大數(shù)據(jù)處理與同時讀寫方法,實例分析了Android操作SQLite時基于事務的數(shù)據(jù)緩存與批量插入技巧,以及同時讀寫的相關實現(xiàn)方法與注意事項,需要的朋友可以參考下2016-07-07
ActivityManagerService廣播并行發(fā)送與串行發(fā)送示例解析
這篇文章主要為大家介紹了ActivityManagerService廣播并行發(fā)送與串行發(fā)送示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03
Android實現(xiàn)Unity3D下RTMP推送的示例
像Unity3D下的RTMP或RTSP播放器一樣,好多開發(fā)者苦于在Unity環(huán)境下,如何高效率低延遲的把數(shù)據(jù)采集并編碼實時推送到流媒體服務器,實現(xiàn)Unity場景下的低延遲推拉流方案。本文介紹幾種RTMP推送的方案2021-06-06

