Android Demo: Telephony Manager


Hello Everyone,

This post shows a very simplified code to be used to fetch Call State using Telephony manager:


<?xml version=“1.0″ encoding=“utf-8″?>
<manifest xmlns:android=“”
    android:versionName=“1.0″ >
    <uses-sdk android:minSdkVersion=“15″ />
    <uses-permission android:name=“android.permission.READ_PHONE_STATE” />
        android:label=“@string/app_name” >
            android:name=“.TelephonyManagerDemoActivity” >
            <intent-filter >
                <action android:name=“android.intent.action.MAIN” />
                <category android:name=“android.intent.category.LAUNCHER” />

package com.codelab.telephony;

import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.TextView;
public class TelephonyManagerDemoActivity extends Activity {
        TextView textView;
         TelephonyManager telephonyManager;
         PhoneStateListener listener;
         /** Called when the activity is first created. */
         public void onCreate(Bundle savedInstanceState) {
           textView = (TextView) findViewById(;
           // Get the telephony manager
           telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
           // Create a new PhoneStateListener
           listener = new PhoneStateListener() {
             public void onCallStateChanged(int state, String incomingNumber) {
               String stateString = ”N/A”;
               switch (state) {
               case TelephonyManager.CALL_STATE_IDLE:
                 stateString = ”Idle”;
               case TelephonyManager.CALL_STATE_OFFHOOK:
                 stateString = ”Off Hook”;
               case TelephonyManager.CALL_STATE_RINGING:
                 stateString = ”Ringing”;
               textView.append(String.format(“\nCallState: %s”, stateString));
           // Register the listener wit the telephony manager
           telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);


<?xml version=“1.0″ encoding=“utf-8″?>
              android:text=“Telephony Manager Demo”
              android:textSize=“22sp” />

Published by


Trekking, Climbing, Camping, Reading, Music,

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s