Android Get mobile Info

Source: Internet
Author: User

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.

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.