Search code examples
androidtelephonymanagercalllog

Second call while on first (goes to voicemail) not logged into CallLog data or listened for - Android, TelephonyManager onCallStateChanged


Here's the scenario:

  1. My phone gets a call, which I answer.

  2. While I'm on that call, a second call comes to my phone. I stay on the first call.

  3. The second call goes straight to voicemail. At no point does the android app seem to get a notification (via onCallStateChanged).

  4. When I hang up the first call the calllog is accessed and something is done with the most recent call (this works fine).

I really need to know about the second call, but as of now, can't seem to get any access / notifications about it. It's not being recorded in the CallLog db, and it's not being "listened" to by the TelephonyManager.

I'm hoping it's just a case of a missing privilege or two.

Anyone able to help me with this?

AndroidManifest.xml permissions (some of the permissions are for other things the app does):

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

onCallStateChanged() code:

switch(mCallState) {

            case TelephonyManager.CALL_STATE_IDLE:
                if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
                    Toast.makeText(getApplicationContext(), "Android: NEW OUTGOING CALL", Toast.LENGTH_LONG).show();
                } else if (state == TelephonyManager.CALL_STATE_RINGING) {
                    Toast.makeText(getApplicationContext(), "Android: NEW INCOMING CALL", Toast.LENGTH_LONG).show();
                }
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
                if (state == TelephonyManager.CALL_STATE_IDLE) {
                    Toast.makeText(getApplicationContext(), "Android: CALL DISCONNECTED", Toast.LENGTH_LONG).show();
                    // Log Phonecall (wait 5 seconds before logging)
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        public void run() {
                            LogPhonecall_Callog();
                        }
                    }, 5000);
                } else if (state == TelephonyManager.CALL_STATE_RINGING) {
                    Toast.makeText(getApplicationContext(), "Android: ANOTHER CALL WAITING", Toast.LENGTH_LONG).show();
                }
                break;

            case TelephonyManager.CALL_STATE_RINGING:
                if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
                    Toast.makeText(getApplicationContext(), "Android: CALL RECEIVED", Toast.LENGTH_LONG).show();
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {
                    Toast.makeText(getApplicationContext(), "Android: MISSED CALL", Toast.LENGTH_LONG).show();
                    // Log Phonecall (wait 5 seconds before logging)
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        public void run() {
                            LogPhonecall_Callog();
                        }
                    }, 5000);
                }
                break;
        }

        mCallState = state;

Solution

  • your phone will be acknowledged by only those calls which come to the phone. for voicemail the call is not coming to the phone, instead it is stored in the switch/server side. so when there is a voicemail sent there is no way (AFAIK) to handle that, you can only hear the voicemail when you call to voicemail number