Recipe Utilizing the Telephony Manager

The telephony API has a TelephonyManager class, which is an Android system service, to access information about the telephony services on the device. Some of the telephony information is permission protected, so access must be declared in the AndroidManifest XML file: <uses-permission android:name="android.permission.READ_PHONE_STATE" />

The main activity is shown in Listing 7.7.

Listing 7.7 src/com/cookbook/hardware.telephony/ package com.cookbook.hardware.telephony;

import; import android.os.Bundle;

import android.telephony.TelephonyManager; import android.widget.TextView;

public class TelephonyApp extends Activity {

TextView tvl;

TelephonyManager telManager;

^Override public void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState); setContentView(R.layout.main); tvl =(TextView) findViewByld(; telManager = (TelephonyManager)


StringBuilder sb = new StringBuilder(); sb.append("deviceid:")

•append(telManager.getDeviceId()).append("\n"); sb.append("device Software Ver:")

•append(telManager.getDeviceSoftwareVersion()).append("\n"); sb.append("Line number:")

•append(telManager.getLine1Number()).append("\n"); sb.append("Network Country ISO:")

•append(telManager.getNetworkCountryIso()).append("\n"); sb.append("Network Operator:")

•append(telManager.getNetworkOperator()).append("\n"); sb.append("Network Operator Name:")

•append(telManager.getNetworkOperatorName()).append("\n"); sb.append("Sim Country ISO:")

•append(telManager.getSimCountryIso()).append("\n"); sb.append("Sim Operator:")

•append(telManager.getSimOperator()).append("\n"); sb.append("Sim Operator Name:")

•append(telManager.getSimOperatorName()).append("\n"); sb.append("Sim Serial Number:")


sb.append("Subscriber Id:")

•append(telManager.getSubscriberId()).append("\n"); sb.append("Voice Mail Alpha Tag:")

•append(telManager.getVoiceMailAlphaTag()).append("\n"); sb.append("Voice Mail Number:")

•append(telManager.getVoiceMailNumber()).append("\n"); tv1.setText(sb.toString());

The main layout XML file is shown in Listing 7.8 and outputs the screen shown in Figure 7.1.

Listing 7.8 res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<TextView android:id="@+id/tv1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />


android hardware 2

devi ce I d : 000000000000000

device Software Ver: nul I

Une number:650-123-4567

Network Country ISO:us

Network Operator:310260

Network Operator Name:Android

Sim Country ISO:us

Sim Operator:310260

Sim Operator Mame:Android

Sim Serial Number:890141032111 ¡8510720

5u bscri b e r Id : 310260000000000

Voice Mail Alpha Tag:VoJcernail

Voice Mall Number:+15552175049

Figure 7.1 Output using the TelephonyManager class.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment