展会信息港展会大全

Android 用APN来获取手机号
来源:互联网   发布日期:2016-01-14 11:28:29   浏览:2082次  

导读:之前很多人说无法完全获取手机号,是因为现在有的卡不能获取,有的卡能获取,现在我们可以换一种思路来考虑问题,就是用VPN的方式请看代码[代码] APNNET.java01/**02* 电信APN列表03* @author wudongdong04*......

之前很多人说无法完全获取手机号,是因为现在有的卡不能获取,有的卡能获取,现在我们可以换一种思路来考虑问题,就是用VPN的方式请看代码

[代码] APNNET.java

01/**

02* 电信APN列表

03* @author wudongdong

04*

05*/

06public class APNNET {

07public static String CTWAP="ctwap";

08public static String CTNET="ctnet";

09}

10/**

11* 电信APN列表

12* @author wudongdong

13*

14*/

15public class APNNET {

16public static String CTWAP="ctwap";

17public static String CTNET="ctnet";

18}

19//获得APN的类型

20

21

22

23/**

24* 获得APN类型

25* @author wudongdong

26*

27*/

28

29public class ApnUtil {

30private static Uri PREFERRED_APN_URI = Uri

31.parse("content://telephony/carriers/preferapn");

32

33/**

34* get apntype

35* @param context

36* @return

37*/

38

39public static String getApnType(Context context){

40String apntype="nomatch";

41Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null,null, null, null);

42c.moveToFirst();

43String user=c.getString(c.getColumnIndex("user"));

44if(user.startsWith(APNNET.CTNET)){

45apntype=APNNET.CTNET;

46}else if(user.startsWith(APNNET.CTWAP)){

47apntype=APNNET.CTWAP;

48}

49return apntype;

50}

51}

52

53/**

54* 获得APN类型

55* @author wudongdong

56*

57*/

58public class ApnUtil {

59private static Uri PREFERRED_APN_URI = Uri

60.parse("content://telephony/carriers/preferapn");

61

62

63/**

64* get apntype

65* @param context

66* @return

67*/

68

69public static String getApnType(Context context){

70String apntype="nomatch";

71Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null,null, null, null);

72c.moveToFirst();

73String user=c.getString(c.getColumnIndex("user"));

74if(user.startsWith(APNNET.CTNET)){

75apntype=APNNET.CTNET;

76}else if(user.startsWith(APNNET.CTWAP)){

77apntype=APNNET.CTWAP;

78}

79return apntype;

80}

81}

[代码] [Java]代码

01/**

02 获得手机号码的话可以传IMSI码到指定接口,接口地址不方便说。但可以透露一点,必须走CTWAP,这也是判断APN类型的原因,发现很多应用如果APN是走代理的话就不能联网,那么再介绍一下用APN设置网络的代理信息。

03 */

04

05 Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,null, null, null,null);

06 c.moveToFirst();

07 String proxy=c.getString(c.getColumnIndex("proxy"));

08

09

10 if (!"".equals(proxy) && proxy!=null) {

11 Properties prop = System.getProperties();

12 System.getProperties().put("proxySet", "true");

13 prop.setProperty("http.proxyHost", c.getString(c.getColumnIndex("proxy")));

14 prop.setProperty("http.proxyPort", c.getString(c.getColumnIndex("port")));

15 String authentication = c.getString(c.getColumnIndex("user"))

16 + ":" + c.getString(c.getColumnIndex("password"));

17 String encodedLogin = Base64.encode(authentication);

18 uc.setRequestProperty("Proxy-Authorization", " BASIC "

19 + encodedLogin);

20 }

21

22 c.close();

赞助本站

人工智能实验室

相关热词: APN 获取手机号

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港