Do mobile phone development, presumably want to get mobile phone number bar, Android has a class Android.telephony.TelephonyManager provide this feature.
Telephonymanager TM = (Telephonymanager) this.getsystemservice (Context.telephony_service);
Numbertext.settext (tm. Getline1number());
The red flag function is able to get the native number.
In addition, Telephonymanager class also provides a variety of access to mobile phone information functions, into the IMEI, IMSI and so on. 、
Look at the code:
Package com.pingan.innovation;
Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.telephony.TelephonyManager;
Import Android.widget.TextView;
public class Phoneinfo extends Activity {
Private TextView Numbertext;
Private TextView Imeitext;
Private TextView Ontext;
Private TextView Sntext;
Private TextView Imsitext;
Private TextView Sstext;
Private TextView Nttext;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Numbertext = (TextView) Findviewbyid (R.id.numbertext);
Imeitext = (TextView) Findviewbyid (R.id.imeitext);
Ontext = (TextView) Findviewbyid (R.id.ontext);
Sntext = (TextView) Findviewbyid (R.id.sntext);
Imsitext = (TextView) Findviewbyid (R.id.imsitext);
Sstext = (TextView) Findviewbyid (R.id.sstext);
Nttext = (TextView) Findviewbyid (R.id.nttext);
Telephonymanager TM = (Telephonymanager) this.getsystemservice (Context.telephony_service);
Numbertext.settext (tm. Getline1number());
Imeitext.settext (tm. Getdeviceid());
Ontext.settext (tm. Getnetworkoperatorname());
Sntext.settext (tm. Getsimserialnumber());
Imsitext.settext (tm. Getsubscriberid());
Sstext.settext (tm. Getnetworkcountryiso());
Nttext.settext (tm. Getnetworkoperator());
}
}
Each of the above functions is obtained by:
Mobile phone number, IMEI, carrier name, SIM card serial number, IMSI, SIM card country, carrier number.
Right, androidmanifest.xml inside also need to add: <uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
This will make it possible to access the Mobile information.
However, after the test on the HTC Hero Real Machine, it was found that the mobile phone number was not available.
The ophone system is tested on the A6188, and no mobile phone number is also taken.