Android development-Get mobile phone SIM card information, androidsim

Source: Internet
Author: User

Android development-Get mobile phone SIM card information, androidsim

TelephonyManager is a service class that manages the call status and network information of a mobile phone. It provides a large number of getXxx () methods to obtain information about the telephone network.

TelephonyManager class overview:

It can be used to access telephone service information on a device. Applications can use this class to determine the telephone service and status and access some types of user information. The application can also register a listener to receive notifications of phone status changes.

You cannot directly instantiate this class. Instead, you can useContext. getSystemService (Context. TELEPHONY_SERVICE)Method to initialize the TelephonyManager instance.

Note that you can access certain phone information permission-protected .. Your application should have some permissions to access the location and status of your mobile phone.

The TelephonyManager class provides the following methods:

 

Public Methods

Int

GetCallState ()

Returns a constant indicating the call status on the device.

CellLocation

GetCellLocation ()

Returns the current location of the device.

Int

GetDataActivity ()

Returns a constant representing the type of the active data connection.

Int

GetDataState ()

Returns a constant indicating the current data connection status.

String

GetDeviceId ()

Return a unique device ID, for example, imei gsm and meid cdma.

String

GetDeviceSoftwareVersion ()

Return the software version number of the device, for example, the IMEI/sv gsm mobile phone number.

String

GetLine1Number ()

Return the phone number of Line 1. For example, MSISDN is used for GSM.

List <NeighboringCellInfo>

GetNeighboringCellInfo ()

Return the information of the adjacent cell of the device.

String

GetNetworkCountryIso ()

Return the country code of the registered network operator.

String

GetNetworkOperator ()

Returned MCC + registered network operator of a multinational company

String

GetNetworkOperatorName ()

Returns the name of the registered Network Carrier.

Int

GetNetworkType ()

Returns a constant representing the radio technology (network type) currently used on the device ).

Int

GetPhoneType ()

Return the type of the device (mobile phone ).

String

GetSimCountryIso ()

Returns the country code of the SIM card carrier.

String

GetSimOperator ()

Return the SIM card of the provider of MCC + Multinational Corporation (mobile country code + mobile network code.

String

GetSimOperatorName ()

The name of the service provider ).

String

GetSimSerialNumber ()

Returns the serial number of the SIM card, if applicable.

Int

GetSimState ()

Returns a constant representing the status of the SIM card device.

String

GetSubscriberId ()

Return a unique user ID. For example, IMSI is a GSM mobile phone.

String

GetVoiceMailAlphaTag ()

Retrieve the letter identifier associated with the voicemail number.

String

GetVoiceMailNumber ()

Return the voicemail number.

Boolean

HasIccCard ()

Boolean

IsNetworkRoaming ()

Returns true. If the device is considered to be roaming the current network, it supports GSM.

Void

Listen (PhoneStateListener listener, int events)

Register a listener object to receive notifications that change the status of a specified phone number.

 


Application instance:

Run:


TelephonyStatus class:


package com.jph.telephonystatus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.ListView;
import android.widget.SimpleAdapter;
/ **
 * Describe: </br>
 * Get Sim Card Information
 * This example uses getXxx () of the object of the TelephonyManager class
 * Method to get mobile SIM card information.
 * @author jph
 * Date: 2014.07.22
 * * /
public class TelephonyStatus extends Activity {
ListView listShow;
// Create an instance of the tManager class
TelephonyManager tManager;
// Declare an array representing the state name of the Sim card
String [] statusName = new String [] {};
// Declaring a state that states that the SIM card is worthy of collection
ArrayList <String> statusValue = new ArrayList <String> ();
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
listShow = (ListView) findViewById (R.id.listShow);
// Get the system's tManager object
tManager = (TelephonyManager) getSystemService (Context.TELEPHONY_SERVICE);
// Get an array representing various state names
statusName = getResources (). getStringArray (R.array.statusName);
// Get an array representing the state of the sim card
String simStatus [] = getResources (). GetStringArray (R.array.simStatus);
// Get an array representing the type of phone
String phoneType [] = getResources (). GetStringArray (R.array.phoneType);
// Get the device number
statusValue.add (tManager.getDeviceId ());
// Get device type
statusValue.add (phoneType [tManager.getPhoneType ()]);
// Get software version
statusValue.add (tManager.getDeviceSoftwareVersion () == null? "Unknown"
: tManager.getDeviceSoftwareVersion ());
// Get the current location of the device
statusValue.add (tManager.getCellLocation () == null? "Unknown"
: tManager.getCellLocation (). toString ());
// Get device call status
switch (tManager.getCallState ()) {
case TelephonyManager.CALL_STATE_IDLE:
statusValue.add ("idle");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
statusValue.add ("Calling");
break;
case TelephonyManager.CALL_STATE_RINGING:
statusValue.add ("Waiting to answer");
break;
default:
break;
}
// Get phone number
statusValue.add (tManager.getLine1Number ());
// Get the country code of the operator
statusValue.add (tManager.getNetworkCountryIso ());
// Get the name of the operator
statusValue.add (tManager.getNetworkOperatorName ());
// Get the network type
statusValue.add (getNetworkType (tManager.getNetworkType ()));
// Get SPN
statusValue.add (tManager.getSimOperatorName (). equals ("")? "" Unknown "
: tManager.getSimOperatorName ());
// Get the serial number of the SIM card
statusValue.add (tManager.getSimSerialNumber ());
// Get SIM card status
statusValue.add (simStatus [tManager.getSimState ()]);
List <Map <String, Object >> listItems = new ArrayList <Map <String, Object >> ();
// Traverse the statusValues collection and change statusNames, statusValues
// The data is encapsulated into the List <Map <String, String >> collection
for (int i = 0; i <statusName.length; i ++) {
Map <String, Object> listItem = new HashMap <String, Object> ();
listItem.put ("name", statusName [i]);
listItem.put ("value", statusValue.get (i));
listItems.add (listItem);
}
SimpleAdapter adapter = new SimpleAdapter (this, listItems, R.layout.line,
new String [] {"name", "value"}, new int [] {R.id.txtName, R.id.txtValue});
// Set Adapter for listShow
listShow.setAdapter (adapter);
}
// Get phone network type
private String getNetworkType (int networkType) {
// TODO Auto-generated method stub
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_1xRTT:
return "1xRTT";
case TelephonyManager.NETWORK_TYPE_CDMA:
return "CDMA";
case TelephonyManager.NETWORK_TYPE_EDGE:
return "EDGE";
case TelephonyManager.NETWORK_TYPE_EHRPD:
return "EHRPD";
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return "EVDO_0";
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return "EVDO_A";
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return "EVDO_B";
case TelephonyManager.NETWORK_TYPE_GPRS:
return "GPRS";
case TelephonyManager.NETWORK_TYPE_HSDPA:
return "HSDPA";
case TelephonyManager.NETWORK_TYPE_HSPA:
return "HSPA";
case TelephonyManager.NETWORK_TYPE_HSPAP:
return "HSPAP";
case TelephonyManager.NETWORK_TYPE_HSUPA:
return "HSUPA";
case TelephonyManager.NETWORK_TYPE_IDEN:
return "IDEN";
case TelephonyManager.NETWORK_TYPE_LTE:
return "LTE";
case TelephonyManager.NETWORK_TYPE_UMTS:
return "UMTS";
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
return "UNKNOWN";
default:
return "UNKNOWN";
}
}
}
Array. xml



<? xml version = "1.0" encoding = "utf-8"?>
<resources>
    <!-Declare an array named statusName->
    <string-array name = "statusName">
        <item> device number </ item>
        <item> Mobile phone system </ item>
        <item> Software version </ item>
        <item> Current location of the device </ item>
        <item> device call status </ item>
        <item> Phone number </ item>
        <item> Country code of the operator </ item>
        <item> Name of the operator </ item>
        <item> Network type </ item>
        <item> SPN </ item>
        <item> Serial number of SIM card </ item>
        <item> SIM card status </ item>
    </ string-array>
    <!-Declare an array named phoneType->
    <string-array name = "phoneType">
        <item> Unknown </ item>
        <item> GSM </ item>
        <item> CDMA </ item>
    </ string-array>
    <!-Declare an array named simSatus->
    <string-array name = "simStatus">
<item> Status unknown </ item>
<item> No SIM card </ item>
<item> PIN locked </ item>
<item> Locked by PUK </ item>
<item> Locked by NetWork PIN </ item>
<item> ready </ item>
    </ string-array>
</ resources>

AndroidManifest. xml



<!-Add access to phone location->
<uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" />
<!-Add access to phone status->
<uses-permission android: name = "android.permission.READ_PHONE_STATE" /> 
For other practical applications of TelephonyManager, refer to: Android development-listening for incoming calls from mobile phones.




How to read SIM card text messages in Android

Open the default information program of the system, click menu, and there is an option "manage SIM card information" after entering it. After clicking it, you can view and edit the SIM card information.
 
In Android, how does one obtain information in the SIM card? If there is a short message in the SIM card or other information written in the SIM card?

I don't know what information you mean? Is it used to obtain the contact information in the SIM?

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.