Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3602602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:46:00+00:00 2026-05-18T20:46:00+00:00

Here is My Whole Code……. BroadcastExample.java package com.example.broadcast; > import android.app.Activity; import > android.content.Context;

  • 0

Here is My Whole Code…….

BroadcastExample.java

 package com.example.broadcast;

> import android.app.Activity; import
> android.content.Context; import
> android.os.Bundle; import
> android.telephony.*; import
> android.util.Log; import
> android.widget.TextView;

public class BroadcastExaple extends Activity {
 TextView textOut;
 TelephonyManager telephonyManager;
 PhoneStateListener listener;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {

  try {

   super.onCreate(savedInstanceState);

   // Get the UI
   textOut = new TextView(this);
   textOut.setText("DEmoBroadCast");
   setContentView(textOut);

   // Get the telephony manager
   telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

   // Register the listener wit the telephony manager
   telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

   // Create a new PhoneStateListener
   listener = new PhoneStateListener() {

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
     Log.d("DEBUG", "Phone listener....");
     String stateString = "N/A";
     switch (state) {
     case TelephonyManager.CALL_STATE_IDLE:
      stateString = "Idle";
      break;
     case TelephonyManager.CALL_STATE_OFFHOOK:
      stateString = "Off Hook";
      break;
     case TelephonyManager.CALL_STATE_RINGING:
      stateString = "Ringing";
      break;
     }
     textOut.append(String.format("\nonCallStateChanged: %s",
       stateString));
    }
   };

  } catch (Exception e) {

  }

 }
}

AndroidManifest.xml

-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.broadcast" android:versionCode="1"
 android:versionName="1.0">
 -<application android:icon="@drawable/icon" android:label="@string/app_name">
  -<activity android:name=".BroadcastExaple" android:label="@string/app_name">
   -<intent-filter>
    -<action android:name="android.intent.action.MAIN" />
    -<category android:name="android.intent.category.LAUNCHER" />
   -</intent-filter>
  -</activity>
 --</application>
 -<uses-prmission android:name="android.permission.READ_PHONE_STATE" />
 -<uses-sdk android:minSdkVersion="7" />
-</manifest> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:46:01+00:00Added an answer on May 18, 2026 at 8:46 pm

    Listener is created after using it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that a whole lot of code cannot fit here, but I am
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
There is something I miss with the notion of Synchronizing code in Android. Scenario
While designing a table my colleague here says that I should avoid identity column
While looking at a micro-optimization question that I asked yesterday ( here ), I
While I'm googling/reading for this answer I thought I would also ask here. I
I've been reading things here and there for a while now about using an
Jeff Atwood wrote about this here , and while I understand the theoretical performance
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.