Skip to content Skip to sidebar Skip to footer

How Can I Determine If There Is A Call Ringing On "line 2" (e.g. Call Waiting)

I'm using an intent-filter to listen to changes in PHONE_STATE

Solution 1:

I found a way to implement this... posting it for "the next guy".

In a nutshell, the phone state moves between three states:

  1. 'IDLE' - You're not using the phone
  2. 'RINGING' - A call is coming in
  3. 'OFF_HOOK' - The phone is off the hook

When a 'RINGING' state is broadcast, it is immediately followed by an IDLE or OFF_HOOK to restore the state to what it was pre-incoming-call.

Put it all together and you end up with this:

package com.telephony;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;

publicclassPhoneStateChangedRecieverextendsBroadcastReceiver {

    privatestaticStringlastKnownPhoneState=null;

    @OverridepublicvoidonReceive(Context context, Intent intent) {
        if(intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {

            //State has changedStringnewPhoneState= intent.hasExtra(TelephonyManager.EXTRA_STATE) ? intent.getStringExtra(TelephonyManager.EXTRA_STATE) : null;

            //See if the new state is 'ringing'if(newPhoneState != null && newPhoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {

                //If the last known state was 'OFF_HOOK', the phone was in use and 'Line 2' is ringingif(lastKnownPhoneState != null && lastKnownPhoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                    ...
                }

                //If it was anything else, the phone is free and 'Line 1' is ringing else {
                    ... 
                }
            }
            lastKnownPhoneState = newPhoneState;
        }
    }
}

Post a Comment for "How Can I Determine If There Is A Call Ringing On "line 2" (e.g. Call Waiting)"