Android reads SIM card information

Source: Internet
Author: User

 

 

Package com. zeph. android. sim;

 

 

Import java. util. ArrayList;

Import java. util. HashMap;

Import java. util. Iterator;

Import java. util. List;

Import java. util. Map;

 

Import android. app. ListActivity;

Import android. OS. Bundle;

Import android. telephony. TelephonyManager;

Import android. widget. ListView;

Import android. widget. SimpleAdapter;

 

Public class GetSIMinfoActivity extends ListActivity {

Private TelephonyManager manager;

Private List <String> item = new ArrayList <String> ();

Private List <String> value = new ArrayList <String> ();

Private ListView mListView;

Private List <Map <String, Object> mData = new ArrayList <Map <String, Object> ();

 

@ Override

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

MListView = getListView ();

Manager = (TelephonyManager) getSystemService (TELEPHONY_SERVICE );

Item. add ("SIM card status ");

Switch (manager. getSimState ()){

Case TelephonyManager. SIM_STATE_READY:

Value. add ("good ");

Break;

Case TelephonyManager. SIM_STATE_ABSENT:

Value. add ("No SIM card ");

Break;

Default:

Value. add ("SIM card locked or unknown ");

Break;

}

 

Item. add ("SIM card serial number ");

If (manager. getSimSerialNumber ()! = Null)

Value. add (manager. getSimSerialNumber ());

Else

Value. add ("cannot be obtained ");

 

Item. add ("SIM card provider Code ");

If (manager. getSimOperator ()! = Null)

Value. add (manager. getSimOperator ());

Else

Value. add ("cannot be obtained ");

 

Item. add ("SIM card provider name ");

If (manager. getSimOperatorName ()! = Null)

Value. add (manager. getSimOperatorName ());

Else

Value. add ("cannot be obtained ");

 

Item. add ("SIM card country ");

If (manager. getSimCountryIso ()! = Null)

Value. add (manager. getSimCountryIso ());

Else

Value. add ("cannot be obtained ");

 

Iterator <String> itItem = item. iterator ();

Iterator <String> itValue = value. iterator ();

While (itItem. hasNext () & itValue. hasNext ()){

HashMap <String, Object> map = new HashMap <String, Object> ();

Map. put ("item", itItem. next ());

Map. put ("value", itValue. next ());

MData. add (map );

}

 

SimpleAdapter adapter = new SimpleAdapter (getApplicationContext (),

MData, R. layout. item_value, new String [] {"item", "value "},

New int [] {R. id. item, R. id. value });

 

MListView. setAdapter (adapter );

 

}

}

 

From Ben Zeph's Code Cloud

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.