Original: http://www.cnblogs.com/growing/archive/2010/11/19/1881372.html
Mobile phone numbers are not all available. Just a part of it can be got. This is because the mobile operator did not write the phone number data to the SIM card. SIM card has only a unique number, for network and device identification that is the IMSI number, the cell phone signal can also be said through this number in the network transmission, not mobile phone number. Just imagine, after your SIM is lost, a new one will change the number. That's because the IMSI number that corresponds to your mobile phone number is modified to the IMSI number of the new SIM card in the mobile operator.
So why do mobile phone number can be displayed?
This is like a variable, and when a mobile operator assigns it a value, it naturally has a value. Do not assign a value naturally empty.
For mobile users, the mobile phone number (MDN) is stored in the operator's server, not in the SIM card. The SIM card only retains IMSI and some authentication information. Every time the mobile phone network registration, will be the form of text messages will be IMSI and verify the information uploaded to the operator's server, the server completed the registration action, will be the form of text messages will be registered to the phone. The content of the issued will vary depending on the conditions.
If the server in the sent message, does not contain the phone number, the phone is unable to obtain the phone number. If the message contains a number, the cell phone will be cached for his use. In addition, for other operators of the SIM card or UIM card, MDN may be saved in the UIM card. 100% It is not possible to obtain a local number.
Mobile China Line, Unicom's card can be taken. The dynamic zone is not accessible. Other cards have not been tried.
There should be a prerequisite for reading the SIM card number. That is, the SIM card has been written to the native number, otherwise it cannot be read.
Specific processing code: (The program in the simulator can not be achieved, must be connected to the mobile phone)
Create Phone Management
Telephonymanager TM = (Telephonymanager)
Establish a connection with a mobile phone
Activity.getsystemservice (Context.telephony_service);
Get cell phone number
String Phoneid = Tm.getline1number ();
Remember to add in manifest file
<uses-permission
Android:name= "Android.permission.READ_PHONE_STATE"/>
*************************************************************************************************************** *********************************************
Http://www.eoeandroid.com/thread-91296-1-1.html
/**
* 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 the type of APN
/** * Obtains APN type * @author Wudongdong */public class Apnutil {private static Uri Preferred_apn_uri = Uri. Parse ("Conte
NT://TELEPHONY/CARRIERS/PREFERAPN "); /** * Get Apntype * @param context * @return/public static string Getapntype (context context) {String apntype= "Nomat
CH ";
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; /** * Obtains APN type * @author Wudongdong */public class Apnutil {private static Uri Preferred_apn_uri = URI. Parse ("C
ONTENT://TELEPHONY/CARRIERS/PREFERAPN "); /** * Get Apntype * @param context * @return/public static string Getapntype (context context) {String apntype= "Nomat
CH ";
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; }
}
Access to mobile phone number can be transmitted IMSI code to the specified interface, the 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 ();