This example describes Android's approach to acquiring mobile phone numbers based on APN. Share to everyone for your reference. Specifically as follows:
Before many people said that can not fully obtain mobile phone number, because there are now some cards can not be obtained, and some cards to obtain, now we can change a way of thinking to consider the problem, is to use the APN way. Please look at the code:
Apnnet.java is as follows:
/** * Telecom APN list * @author wudongdong * */public class Apnnet {public static String ctwap= "Ctwap";
public static String ctnet= "Ctnet";
/** * Telecom APN list * @author wudongdong * */public class Apnnet {public static String ctwap= "Ctwap";
public static String ctnet= "Ctnet"; }//Get APN type/** * Get APN type * @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= ' no
Match ";
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; /** * Get APN Type * @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= ' no
Match ";
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;
}
}
The Java code is as follows:
/**
access to mobile phone number can be transmitted IMSI code to specify the interface, interface address is not convenient to say. But can reveal a point, must go Ctwap, this is the reason to judge the type of APN, found that many applications if APN is to go agent words can not be networked, then introduce the APN set up the network agent information.
*/
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 ();
I hope this article will help you with your Android program.