Android基于APN獲取手機(jī)號(hào)的方法
本文實(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)文章
Android 大文件切割與合并的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 大文件切割與合并,實(shí)現(xiàn)了很多發(fā)文件和視頻的切割,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11Android中fragment與activity之間的交互(兩種實(shí)現(xiàn)方式)
本篇文章主要介紹了Android中fragment與activity之間的交互(兩種實(shí)現(xiàn)方式),相信對(duì)大家學(xué)習(xí)會(huì)有很好的幫助,需要的朋友一起來(lái)看下吧2016-12-12OKhttp攔截器實(shí)現(xiàn)實(shí)踐環(huán)節(jié)源碼解析
這篇文章主要為大家介紹了OKhttp攔截器實(shí)現(xiàn)實(shí)踐環(huán)節(jié)源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案
這篇文章主要為大家介紹了Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12Android 再按一次返回鍵退出程序?qū)崿F(xiàn)思路
用戶退出應(yīng)用前給出一個(gè)提示是很有必要的,因?yàn)榭赡苁怯脩舨⒉徽娴南胪顺?,而只是一不小心按下了返回鍵,大部分應(yīng)用的做法是在應(yīng)用退出去前給出一個(gè)Dialog提示框;個(gè)人覺(jué)得再按一次返回鍵退出程序很有必要,接下來(lái)介紹一些簡(jiǎn)單實(shí)現(xiàn)2013-01-01android上的一個(gè)網(wǎng)絡(luò)接口和圖片緩存框架enif簡(jiǎn)析
android上的一個(gè)網(wǎng)絡(luò)接口和圖片緩存框架enif詳細(xì)介紹:底層網(wǎng)絡(luò)接口采用apache的httpclient連接池框架、圖片緩存采用基于LRU的算法等等,需要了解的朋友可以詳細(xì)參考下2012-12-12android 自定義ScrollView實(shí)現(xiàn)背景圖片伸縮的實(shí)現(xiàn)代碼及思路
本文純屬個(gè)人見(jiàn)解,是對(duì)前面學(xué)習(xí)的總結(jié),如有描述不正確的地方還請(qǐng)高手指正~,首先還是按照通例給大家看下示例.2013-05-05