views:

406

answers:

2

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?

+2  A: 

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.

Alnitak
Hi Alnitak, I have come across a major issue with this on the HTC Hero, I use setResultData(null) to block the call however it doesn't seem to properly block the call. It blocks it ok but it buts a dialer icon in the used apps screen(hold down the home key) and when you click on this it appears to try to call again and disspears then, have yo come across anything like this? Works fine in vanilla Android but having major issues on the HTC Hero
Donal Rafferty
I don't have a Hero. It's possible that their special shell is also intercepting outbound call attempts, at a higher priority than your application. Try changing your BroadcastReceiver's priority.
Alnitak
A: 

Hi Alnitak,

I am trying to do something similiar to what you have here, I want to trap out going calls, block them and then redirect the number over a cheaper option than GSM if available.

From your code you have posted I cant see how you block the call before you let the user choose the new destination, is that in a different piece of code?

Donal Rafferty
Donal - see http://code.google.com/p/enumdroid/source/browse/trunk/src/uk/nominet/android/phone/ENUMReceiver.java - essentially you just call `setResultData(null)` to block the original call
Alnitak