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

  • SEARCH
  • Home
  • 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 5944753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:35:03+00:00 2026-05-22T16:35:03+00:00

I am using the PhoneState Action in my Android app, but there is a

  • 0

I am using the PhoneState Action in my Android app, but there is a problem, Wen I get the number from an incoming call during ringing state, it works fine but after I pick the call my BroadCastReceiver crashes because the intent bundle is null coz there is no number to fetch.

How do I make sure I am listening to only to the Ringing state and not any other weird stuff:

Here is my code:

package com.messageHider;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class incomingCallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle=intent.getExtras();
        String number=bundle.getString("incoming_number");
        dbConnection connection=new dbConnection(context);
        SQLiteDatabase db=connection.getReadableDatabase();
        Cursor cursor=db.query(dbConnection.TABLE_CONTACTS, null, dbConnection.CONTACT+"=?",new String[]{number}, null, null, null);
        cursor.moveToFirst();
        int count=cursor.getCount();
        Toast.makeText(context,String.valueOf(count), Toast.LENGTH_LONG).show();
    }
}

Here is my manifest:

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".messageHider"
              android:label="@string/app_name">

    </activity>
    <activity android:name=".sms"/>
    <activity android:name=".viewsms"/>
    <activity android:name=".hiddenMessages"></activity>
    <activity android:name=".viewContacts">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name=".smsService"/>
    <receiver android:name=".smsReceiver">
        <intent-filter android:priority="100">
            <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
        </intent-filter>
    </receiver>
    <receiver android:name=".smsSentReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_SENT"/>
        </intent-filter>
    </receiver>
    <receiver android:name=".incomingCallReceiver">
        <intent-filter android:priority="100">
            <action android:name="android.intent.action.PHONE_STATE"/>
        </intent-filter>
    </receiver>
</application>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

  • 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-22T16:35:03+00:00Added an answer on May 22, 2026 at 4:35 pm

    From documentation about EXTRA_INCOMING_NUMBER:

    The lookup key used with the
    ACTION_PHONE_STATE_CHANGED broadcast
    for a String containing the incoming
    phone number. Only valid when the new
    call state is RINGING.

    This means your code should be:

    public class incomingCallReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {            
            Bundle bundle=intent.getExtras();
            if( bundle != null ){
                 String number=bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                 if( number != null ){
                     dbConnection connection=new dbConnection(context);
                     SQLiteDatabase db=connection.getReadableDatabase();
                     Cursor cursor=db.query(dbConnection.TABLE_CONTACTS, null, 
                                            dbConnection.CONTACT+"=?",
                                            new String[]{number}, 
                                            null, null, null);
                     cursor.moveToFirst();
                     int count=cursor.getCount();
                     Toast.makeText(context,String.valueOf(count), Toast.LENGTH_LONG).show();
                 }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen several questions regarding SocketException when using Android, but none of them
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using jQuery, how do I get the value from a textbox and then load
I’d like to start a service by using PHONE_STATE when an incoming call gets
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
using VB.Net2010 I need to call a C# DLL The problem I have is
Using mercurial, I've run into an odd problem where a line from one committer
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters

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.