国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

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

2020-04-11 11:28:24
字體:
來源:轉載
供稿:網友

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

之前很多人說無法完全獲取手機號,是因為現在有的卡不能獲取,有的卡能獲取,現在我們可以換一種思路來考慮問題,就是用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類型的原因,發現很多應用如果APN是走代理的話就不能聯網,那么再介紹一下用APN設置網絡的代理信息。 */  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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿瓦提县| 兰州市| 阳新县| 象山县| 蒙阴县| 扬州市| 六盘水市| 嘉定区| 卫辉市| 静宁县| 阿尔山市| 哈密市| 鲜城| 民丰县| 浠水县| 浙江省| 都安| 日喀则市| 鹤山市| 牙克石市| 全椒县| 阿瓦提县| 土默特左旗| 兖州市| 林口县| 五寨县| 永新县| 内黄县| 剑阁县| 泽普县| 宁津县| 青田县| 麻城市| 塔河县| 湄潭县| 凤山县| 平泉县| 汤阴县| 安陆市| 县级市| 民乐县|