Question

I have a BroadcastReceiver catching ACTION_NEW_OUTGOING_CALL events.

In the onReceive() method I'm sending the supplied number to a new ListActivity, where the user gets to choose various new destination numbers from a list.

When the user selects a new number from the list I'm then starting a new ACTION_CALL intent with the new number in the URI field. Alternatively, the result might be the original number.

Whatever the new number is, it has to be dialled immediately and not processed any further.

How can I let the BroadcastReceiver know that this resulting number shouldn't be processed yet again?

Was it helpful?

Solution

I resolved this by implementing a "Bypass Prefix" in my BroadcastReceiver. If my client app wants to call a number directly it simply prepends the prefix before invoking the ACTION_CALL Intent.

If the dialed number has the (hard coded) prefix, the BroadcastReceiver strips the prefix and allows the call to proceed as normal:

public void onReceive(Context context, Intent intent)
{
    String action = intent.getAction();
    if (Intent.ACTION_NEW_OUTGOING_CALL.equals(action)) {
        String number = getResultData();
        if (number.startsWith(BYPASS_PREFIX)) {
             setResultData(number.substring(BYPASS_PREFIX.length()));
        } else {
             // do additional processing
        }
    }
}

This solves two problems in one go - not only does this stop the call looping, it also gives me a way to bypass the additional processing for specific numbers by storing the prefix in their phone book entries.

OTHER TIPS

The onReceive() method in Broadcast receiver receives an Intent as an argument. Extract the Bundle from the Intent using Intent.getExtras(). This Bundle contains 3 key-value pairs as follows :

  1. android.phone.extra.ALREADY_CALLED = null
  2. android.intent.extra.PHONE_NUMBER = 98xxxxxx98
  3. android.phone.extra.ORIGINAL_URI = tel:98xxxxxx98

98xxxxxx98 is the number dialled by the user.

When the onReceive() is called again, this number changes to 98xxxxxx98* or 0* By checking for the asterisk(*) at the end of the dialled number, it can be inferred if the onReceive() method is called for the first time or the next subsequent times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top