How to get phone number from an incoming call?

How do I get the phone number when there is an incoming call in Android?

  • Soft keyboard enter key event handle
  • Creating a custom editText with tag-like feature
  • Why onDraw is not called after invalidate()?
  • Check if directory exist on android's sdcard
  • NDK vs JAVA performance
  • How to debug Android's native browser (not Chrome) on a desktop machine?
  • Show Yes/No-Dialog instead of OK/Cancel
  • Android: Quitting the Looper?
  • Multiple Notifications Getting Delivered From GCM
  • How to implement In-App Billing in an Android application?
  • Sending and receiving text using android emulator
  • Error:(26, 0) Gradle DSL method not found: 'runProguard()'
  • 6 Solutions collect form web for “How to get phone number from an incoming call?”

    Make a Broadcast receiver say ServiceReceiver assign its action in Manifest.

    <receiver android:name=".ServiceReceiver" >
            <action android:name="android.intent.action.PHONE_STATE" />

    Add a PhoneStateListener to your TelephonyManager, PhoneStateListener having override onCallStateChanged() with Incoming number parameter. Thats it.


    public class ServiceReceiver extends BroadcastReceiver {
        public void onReceive(final Context context, Intent intent) {
            TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            telephony.listen(new PhoneStateListener(){
                public void onCallStateChanged(int state, String incomingNumber) {
                    super.onCallStateChanged(state, incomingNumber);
                    System.out.println("incomingNumber : "+incomingNumber);

    Following solution helped me retrieve the incoming and outgoing phone numbers.

    Things to include in manifest :

    1) Permission :

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

    2) A broadcast receiver:

    <receiver android:name=".AnswerCallBroadcastReceiver">
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />

    Things to include in BroadcastReceiver class :

        public class AnswerCallBroadcastReceiver extends BroadcastReceiver {
            public void onReceive(Context arg0, Intent arg1) {
                    String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE);
                        Log.d(TAG, "Inside Extra state off hook");
                        String number = arg1.getStringExtra(TelephonyManager.EXTRA_PHONE_NUMBER);
                        Log.e(TAG, "outgoing number : " + number);              
                    else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)){   
                        Log.e(TAG, "Inside EXTRA_STATE_RINGING");
                        String number = arg1.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                        Log.e(TAG, "incoming number : " + number);
                    else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                        Log.d(TAG, "Inside EXTRA_STATE_IDLE");

    Please refer to this question: Retrieve incoming call’s phone number in Android

    And also have a look at this answer too: how do I get the phone number from incoming call?

    you can find solution here

    Bundle bundle = intent.getExtras();
    String phoneNr= bundle.getString("incoming_number");

    This will defiantly help you .

    Here is an implementation which will allow you to retrieve the phone number if it is an incoming phone call as incoming Number and also when the call is FINISHED – note the Handler() code.

    private class PhoneCallListener extends PhoneStateListener {
    private boolean isPhoneCalling = false;
    public void onCallStateChanged(int state, String incomingNumber) {
        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(LOG_TAG, "OFFHOOK");
            isPhoneCalling = true;
        if (TelephonyManager.CALL_STATE_IDLE == state) {
            // run when class initial and phone call ended, need detect flag
            // from CALL_STATE_OFFHOOK
            Log.i(LOG_TAG, "IDLE number");
            if (isPhoneCalling) {
                Handler handler = new Handler();
                //Put in delay because call log is not updated immediately when state changed
                // The dialler takes a little bit of time to write to it 500ms seems to be enough
                handler.postDelayed(new Runnable() {
                    public void run() {
                        // get start of cursor
                          Log.i("CallLogDetailsActivity", "Getting Log activity...");
                            String[] projection = new String[]{Calls.NUMBER};
                            Cursor cur = getContentResolver().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc");
                            String lastCallnumber = cur.getString(0);
                isPhoneCalling = false;

    And then add and initialise the listener in your onCreate or onStartCommand code:

      PhoneCallListener phoneListener = new PhoneCallListener();
    TelephonyManager telephonyManager = (TelephonyManager) this

    By using the accepted answer, you will register a new listener with every change of the call state. It will result in multiple onCallStateChanged calls for same event.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.