[Transferred] to read phone number on the

2011-01-11  来源:本站原创  分类:Mobile  人气:157 

Original: http://labs.chinamobile.com/mblog/427_62947

1. An error code from our discussion leads to:
android open API provides access methods, we all know the methods used TelephonyManager provided, but some understanding is wrong, as the domestic forum of a larger andorid examples provided to an error:
Post as http://www.eoeandroid.com/thread-14027-1-3.html, including implementation code no comment, only in accordance with the definition of variables to determine:
TelephonyManager tm = (TelephonyManager) this.getSystemService (Context.TELEPHONY_SERVICE);
String deviceid = tm.getDeviceId ();
String tel = tm.getLine1Number (); / / Remove the user's mobile phone number, I added
String imei = tm.getSimSerialNumber (); / / Remove the IMEI, I added
String imsi = tm.getSubscriberId (); / / Remove the IMSI, I added

Then the above error was: String imei = tm.getSimSerialNumber (); / / Remove IMEI
IMEI is the phone's serial number, how through getSimSerialNumber () method to obtain, then check andorid source can be seen:
http://www.netmite.com/android/mydroid/frameworks/base/telephony/java/android/telephony/TelephonyManager.java
Clearly seen from the comments in this function is to take the SIM card serial number, that is ICCID, and he was wrong.

/**
     * Returns the serial number of the SIM, if applicable.
     * <p>
     * Requires Permission:
     *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     */
    public String getSimSerialNumber() {
        try {
            return getSubscriberInfo().getSimSerialNumber();
        } catch (RemoteException ex) {
        }
        return null;
    }
2. Several definitions. Description :
 We talk about and cell phones. card number related data including IMSI,MSISDN,ICCID,IMEI
IMSI:international mobiles subscriber identity International mobile subscriber number identification ,
 Generally we do not know, GSM must be written on the card related files :
MSISDN:mobile subscriber ISDN User ID, this is what we say 139,136 That number :
ICCID:ICC identity Integrated circuit card identification, this is a physical numbers that uniquely identifies a card :
IMEI:international mobile Equipment identity Mobile phone unique identifier :

3. Well, we look to achieve TelephonyManager.java andorid source:
getDeviceId () get IMEI number is not controversy.
/ **
* Returns the unique device ID, for example, the IMEI for GSM
* Phones.
*
* <p> Requires Permission:
* {@ Link android.Manifest.permission # READ_PHONE_STATE READ_PHONE_STATE}
* /
public String getDeviceId () {
try {
return getSubscriberInfo (). getDeviceId ();
} Catch (RemoteException ex) {
}
return null;
}
getLine1Number () to take MSISDN, the need for two points, 1 why this function is called getLine1Number (), when implemented as andorid GSM and CDMA should be divided into the, GSM mobile phone to use this function, CDMA will be implemented by the other.
2 The specific method will lead to MSISDN can get to the end, a function of the getSubscriberInfo (). GetLine1Number () to achieve, we look for the following.
/ **
* Returns the phone number string for line 1, for example, the MSISDN
* For a GSM phone.
* <p>
* Requires Permission:
* {@ Link android.Manifest.permission # READ_PHONE_STATE READ_PHONE_STATE}
* /
public String getLine1Number () {
try {
return getSubscriberInfo (). getLine1Number ();
} Catch (RemoteException ex) {
}
return null;
}
Find a private IPhoneSubInfo getSubscriberInfo () {
/ / Get it each time because that process crashes a lot
return IPhoneSubInfo.Stub.asInterface (ServiceManager.getService ("iphonesubinfo"));
}
An interface to find a PhoneSubInfo.java:
/ **
* Retrieves the unique device ID, eg, IMEI for GSM phones and MEID for CDMA phones.
* /
public String getDeviceId () {
mContext.enforceCallingOrSelfPermission (READ_PHONE_STATE, "Requires READ_PHONE_STATE");
return mPhone.getDeviceId ();
}
Previously defined the Phone mPhone, find Phone.java:
/ **
* Retrieves the unique sbuscriber ID, eg, IMSI for GSM phones.
* /
String getSubscriberId ();
Turned out to be interface, a concrete realization of that PhoneProxy.java
public String getSubscriberId () {
return mActivePhone.getSubscriberId ();
}
MActivePhone is an instance of this phone, I'm crazy, so that GSMPHONE. With the realization in java:
public String getSubscriberId () {
return mSIMRecords.imsi;
}

public String getIccSerialNumber () {
return mSIMRecords.iccid;
}

public String getLine1Number () {
return mSIMRecords.getMsisdnNumber ();
Seen from above, it should be documented through the SIM card, get the relevant data from which to see:
public void handleMessage (Message msg) this function was the real deal, look at the focus:

case EVENT_GET_MSISDN_DONE:
isRecordLoadResponse = true;

ar = (AsyncResult) msg.obj;

if (ar.exception! = null) {
Log.d (LOG_TAG, "Invalid or missing EF [MSISDN]"); / / should be from the sim card taken out EFmsisdn file
break;
}

adn = (AdnRecord) ar.result;

msisdn = adn.getNumber ();
msisdnTag = adn.getAlphaTag ();

Log.d (LOG_TAG, "MSISDN:" + msisdn);
break;

The following details will be analyzed, the problem boils down to whether the file from the SIM card out EFmsisdn phone number, and unfortunately the general user number operators will not write in this file, why?
Because this phone number is on the user to buy the card and opened only when the corresponding IMSI and MSISDN's, the card is only produced when the IMSI, you do not know the phone number the user like that, it generally does not correspond to the first IMSI and MSISDN, an immediate do not correspond to write this document.

4. Summarize:
TelephonyManager tm = (TelephonyManager) this.getSystemService (Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId (); / / Remove IMEI
String tel = tm.getLine1Number (); / / Remove the MSISDN, may be empty
String imei = tm.getSimSerialNumber (); / / Remove ICCID
String imsi = tm.getSubscriberId (); / / Remove the IMSI

相关文章
  • [Transferred] to read phone number on the 2011-01-11

    Original: http://labs.chinamobile.com/mblog/427_62947 1. An error code from our discussion leads to: android open API provides access methods, we all know the methods used TelephonyManager provided, but some understanding is wrong, as the domestic fo

  • Apache Configuration 2010-05-14

    WWW server under the well-known research firm's survey, 50 percent more than the world's WWW server are using Apache, is the world's number one WEB server. Apache birth very dramatic. When the NCSA WWW server projects to a halt, those using the NCSA

  • The origin of various coding 2010-08-11

    Transfer from: http://www.javaeye.com/topic/351135 do layout changed. ANSI: 8 bytes can be combined to a total of 256 (2 to the 8th power) different states. Number from 0 to 32 kinds of states, which are provided for special purposes, once the termin

  • Do not erase all the pain for customers 2010-10-21

    Customer feedback to see all the discontent in the matters listed, you frowned: line too long, the background music too loud, the company can accept the limited payment cards ... ... you pick up the phone, ready to call the department began a reforms

  • PHP with MySQL database a permanent connection is non-operational 2011-03-23

    PHP programmer should know that you can connect MySQL database using mysql_pconnect (permanent link) function, using the database can improve the efficiency of permanent connections, but the practical application of permanent database connections oft

  • [Transferred] the common software version number and name 2010-08-31

    Keywords: version, code, rc, ga 1, RC, GA RC: is the Release Candidate (release candidate) of the abbreviation GA: is General Availability, the official release of version Alpha: closed beta version. Alpha is the first Greek letter in English homopho

  • [Transferred] to return to the database schema objects within the object identification number - OBJECT_ID (Transact-SQL) 2010-12-16

    [Switched from MSDN: http://msdn.microsoft.com/zh-cn/library/ms190328.aspx ] Back to the database schema objects within the object identification number. Important: OBJECT_ID can not query non-use within the framework of objects (such as DDL triggers

  • [Transferred] to do online video recording using FMS 2010-02-11

    Preparation tools: Flash Media Server .. Flash 8 & & Flash 8 Player (-______-) A camera, a microphone. Open FLASH, FLASH create a new document. CTRL + L transferred out library .. upper right corner of the library has a triangle count. And then se

  • [Transferred] to answer all doubts on the Oracle license, organize various users of the statement. 2010-03-23

    And answer your doubts on the Oracle license, organize various users of the statement. Often discussed the recent Forum ORACLE database to see the license issue, I think a lot of friends at the time of purchase of ORACLE products, There may be some d

  • Oracle job management [transferred from www.bitsCN.com] 2010-03-29

    SVRMGR> select * from dba_jobs; Initialization parameters job_queue_processes alter system set job_queue_processes = 39 scope = spfile; / / maximum value can not exceed 1000; job_queue_interval = 10 / / dispatch operations refresh rate in seconds DBA

  • [Transferred] to write poorly and linux notes 2010-04-14

    linux directory structure / Root / Bin common command binary file directory / Boot storage system start to read the files, including the core (kernel), including / Boot / grub / menu.lst GRUB settings / Boot / vmlinuz kernel / Boot / initrd RAM Disk

  • Transferred from site performance optimization summary 2010-06-04

    Summary transferred from site performance optimization. 1. To use stored procedures (if stored in a program with the exec process parameters, such implementation does not seem much faster) is pre-compiled in the database, nor need to spend a lot of t

  • Mac OSX adjusted maximum number of socket connections 2010-07-24

    The default maximum number of socket connections is 128, so do with Mac OSX server may encounter Joel Raymont problems The maximum number of socket connections to Mac transferred to 512 changes the command as follows: sudo sysctl -w kern.ipc.somaxcon

  • oracle sql statement, Bank of China transferred the dynamic 2010-11-12

    create table T_TEST ( CITY VARCHAR2 (255) not null, YEAR NUMBER (4) not null, MONTH NUMBER (2) not null, SELL_AMOUNT NUMBER (26,2) ) comment on table T_TEST is 'the World Alliance of each month in the main core of the city's sales amount'; comment on

  • [Transferred] an instance of television promotion and Internet Marketing Comparison 2010-11-25

    http://www.williamlong.info/archives/2401.html The evening of November 7, CCTV "Focus" program aired "Secret Internet Marketing", the promoter and the network to the network on behalf of the network of thugs for the PR industry in the

  • sql row and column transferred to switch 2011-05-30

    Original Address: http://edu.codepub.com/2010/0729/24638_3.php Line transferred to the column switch is often encountered in the development process issues. Transferred to the general line through the CASE WHEN statement to achieve, SQL SERVER 2005 c

  • transferred sql row and column switch 2011-05-30

    Original Address: http://edu.codepub.com/2010/0729/24638_3.php Line transferred to the column switch is often encountered in the development process issues. Transferred to the general line through the CASE WHEN statement to achieve, SQL SERVER 2005 c

  • (To) Asterisk FXO analog lines calling number identification (caller ID) 2011-05-26

    CID (CallerID, CLID, Caller ID, caller ID) are frequently encountered in the actual use of another common problem, caller ID format into FSK (U.S. standard) or DTMF way. Caller ID may be sent back before the first tone ring, may also after the first

  • ORA-00018: maximum number of sessions exceeded solutions 2011-07-25

    Application running for some time, occasional System Runtime Error: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: ORA-00018: maximum number of sessions exceeded error, ORA-00018 oracle session and the proc

  • A. TCP / IP protocol introduction - transferred 2011-06-16

    One, TCP / IP protocol introduced Introducing the HTTP protocol, before briefly about the TCP / IP protocol-related content. TCP / IP protocol is layered, from the bottom to the application layer are: the physical layer, link layer, network layer, tr