Number of outgoing calls

Here is the code I am using to get the incoming, outgoing call number:

if(arg1.getAction().equals("android.intent.action.PHONE_STATE")){

                String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE);

                if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                    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");
                }   
            }

      

But TelephonyManager.EXTRA_PHONE_NUMBER is giving me error, so I can't get outgoing call number! In addition to this, I would also like to restore the call duration. Please help me.

+3


source to share


1 answer


From this question mentioned here, How do I detect incoming calls on an Android device?

The action NEW_OUTGOING_CALL

will give you the outgoing call number, for the incoming call your code will work fine.

if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
            savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
        }

      



In addition to this, I would also like to restore the duration of the call. Please help me

You can get the duration of calls only from the call log or if you consider the above answer from the link in onOutgoingCallEnded

, you can subtract the start and end times, but this again won't give you the exact time because it OFF_HOOK

starts when the call is not made when connecting or answering a call so it's best to stick with the call log for the exact duration.

So if you are using the above code from the link and want to detect the duration as soon as it starts onOutgoingCallEnded

, wait for the second adn, then read from the call log, after which you will get the last entry, which you will always get the previous entry from the call log.

+1


source







All Articles