Android mobile phone number acquisition problem use APN to get mobile phone number

Source: Internet
Author: User


Original article: http://www.cnblogs.com/growing/archive/2010/11/19/1881372.html

Not all mobile phone numbers can be obtained. Only some of them can be obtained. This is because the mobile operator did not write the data of the mobile phone number into the SIM card. the SIM card only has a unique ID for the network and device to identify, that is, the imsi number. The mobile phone signal can also be said to be transmitted through this number in the network, not the mobile phone number. Imagine if your SIM is lost, will a new one be replaced? No, it is because the imsi number corresponding to your mobile phone number is changed to the imsi number of the new SIM card in the mobile operator.
Why can I display some mobile phone numbers?
This is like a variable. When a mobile operator assigns a value to it, it naturally has a value. Null if no value is assigned.
For mobile users, the mobile phone number (MDN) is stored on the carrier's server instead of the SIM card. The SIM card only retains imsi and some verification information. Each time a mobile phone is registered, it uploads imsi and verification information to the carrier's server via text message. After the server completes the registration, the registration result will be sent to the mobile phone via text message. The content delivered varies according to different conditions.
If the server sends a text message that does not contain the phone number, the phone number cannot be obtained. If the phone number is included in the text message, the phone will cache it for him to use. In addition, for SIM cards or uimcards of other operators, MDN may be stored in the uimcard. 100% it is unlikely that a local number can be obtained.
China Unicom's card can be obtained from China Mobile shenzhouxing. The motion zone cannot be obtained. Other cards have not been tried yet.
The premise is that the SIM card number can be read, that is, the SIM card has been written into the local number, otherwise it cannot be read.

Specific processing code: (the program cannot be implemented on the simulator and must be connected to the mobile phone)

// Create telephone management

Telephonymanager TM = (telephonymanager)

// Establish a connection with the mobile phone
Activity. getsystemservice (context. telephony_service );

// Obtain the mobile 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
/ **
* 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 = "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;
}
}

/ **
* 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 = "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;
}
}
 If you get a mobile phone number, you can pass the IMSI code to the designated interface, the interface address is not convenient to say. But it can be revealed that you must go to CTWAP, which is also the reason for judging the type of APN. It is found that many applications cannot connect to the network if the APN is a proxy. Then introduce the proxy information for setting the network with 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 ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.