Android Read SIM card information

Source: Internet
Author: User

Application of Telephonymanager

The main function of mobile phone is to call, if there is no telecommunications company to provide SIM card, it can not be normal to make calls, then, we have what method can get SIM card status and related information?

The Telephonymanager (Android.telephony.TelephonyManager) object in the Android API provides several ways to quickly get the status of a SIM card and related information.
The program takes Getsystemservice (Telephony_service) to obtain the Telephonymanager object, Telephonymanager provides the method to obtain the SIM card status and related information, The information obtained is stored in the custom myadapter, and finally the information in the Myadpter is displayed in the ListView with Setlistadapter ().

1 Import Android.telephony.TelephonyManager;
2
3
4
5 public class Ex05_18 extends Listactivity {
6
7 Private Telephonymanager Telmgr;
8
9 Private list<string> item=new arraylist<string> ();
10
One private list<string> value=new arraylist<string> ();
12
13
14
@SuppressWarnings ("Static-access")
16
@Override
18
public void OnCreate (Bundle savedinstancestate) {
20
Super.oncreate (savedinstancestate);
22
23/* Load into main.xml Layout */
24
Setcontentview (R.layout.main);
26
Telmgr = (Telephonymanager) getsystemservice (Telephony_service);
28
29/* Writes the obtained information to the list */
30
31/* Get SIM card status */
32
Item.add (Getresources (). GetText (R.string.str_list0). toString ());
34
if (Telmgr.getsimstate () ==telmgr.sim_state_ready) {
36
Panax Notoginseng Value.add ("good");
38
if (Telmgr.getsimstate () ==telmgr.sim_state_absent) {
40
Value.add ("No SIM card");
42
+} else {
44
Value.add ("SIM card is locked or unknown");
46
47}
48
49/* Get SIM card number */
50
Wuyi Item.add (Getresources (). GetText (R.string.str_list1). toString ());
52
if (Telmgr.getsimserialnumber ()!=null) {
54
Value.add (Telmgr.getsimserialnumber ());
56
(+)} else {
58
Value.add ("cannot be obtained");
60
61}
62
63/* Get SIM card supplier code */
64
Item.add (Getresources (). GetText (R.string.str_list2). toString ());
66
if (Telmgr.getsimoperator (). Equals ("")) {
68
Value.add ("Unable to obtain");
70
+} else {
72
Value.add (Telmgr.getsimoperator ());
74
75}
76
77/* Get SIM card supplier Name */
78
Item.add (Getresources () GetText (R.STRING.STR_LIST3). toString ());
80
Bayi if (Telmgr.getsimoperatorname (). Equals ("")) {
82
Value.add ("Unable to obtain");
84
+} else {
86
Value.add (Telmgr.getsimoperatorname ());
88
89}
90
91/* Get SIM card country */
92
Item.add (Getresources (). GetText (R.STRING.STR_LIST4). toString ());
94
if (Telmgr.getsimcountryiso (). Equals ("")) {
96
Value.add ("cannot be obtained");
98
* Else {
100
101 Value.add (Telmgr.getsimcountryiso ());
102
103}
104
105/* Use a custom myadapter to pass data to listactivity */
106
107 Setlistadapter (New Myadapter (This,item,value));
108
109}
110
111
112
113}

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.