1

I am trying to intercept an outgoing call and give the user an option to abort or continue the call via a dialog.

The first step is obviously writing a BroadcastReceiver that registers for NEW_OUTGOING_CALL, which I have done successfully.

I have also created an Activity based on the Dialog theme that presents the user with the Abort/Continue buttons. My current code has no problem launching this from the broadcast receiver when an outgoing call is placed.

Where I am struggling is with holding the call action until the user has a chance to respond. While you can call startActivity from the onReceive method of a BroadcastReceiver, that call returns immediately which, in my case, means that the call goes through while the dialog is being presented.

The Android "Receiver Lifecycle" information has a fairly strict take on this, saying:

In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service.

I understand the general badness of blocking as well as displaying UI elements in a broadcast receiver. I also understand that Android is generally asynchronous and, as such, this is a bit odd. However, in this case, I feel it is appropriate. A notification will most definitely not solve my problem. Thus I'm hoping that the smart people here at StackOverflow can find a way despite Google saying it cannot be done.

Also, Google Voice seems to do it.

Anyway, I have scoured StackOverflow and the rest of the net for an answer to this. While there are a ton of related questions, I have yet to find one that fully captures the nature of my problem except for this one, which is dead-on, but the only answer completely missed the point.

One option that I have considered is to abort the original call and then place a new one if the user chooses "continue". I assume I'll have to somehow signal my broadcast receiver not to show the dialog for this case. This should be doable, but it feels overly complicated.

Thanks in advance for any help.

2
  • In general, if youre trying to game the system, your code is going to get complicated. I actually do not see other solutions, but the one you descrivbd.
    – inazaruk
    Jun 19, 2011 at 11:09
  • A bit more information. In API level 11 (3.0), they seem to have fixed this problem with the introduction of the BroadcastReceiver.PendingResult class and the goAsync call. With this, the path is obvious. Unfortunately I'm trying to do this for pre-11 devices.
    – Scot
    Jun 19, 2011 at 11:14

1 Answer 1

0

I guess you can use the call intent filters to invoke your activity if user requires .. that will create an asking dialog it will remain der until user gives an input. Correct me If I m wrong.

3
  • I'm not sure I completely understand your response. I am already using the NEW_OUTGOING_CALL intent to invoke my code the user places a call. That is not a problem. The problem is after the user places a call, I have to decide what to do with the outgoing call inside of the onReceive method, which only gives me time to launch a dialog, not to wait for user input.
    – Scot
    Jun 20, 2011 at 2:06
  • hmm I guess this could be reason for the issue.. see broadcast receivers acts as registered notifier for a particular event. Now you and the default telephonic application has registered for receiving the New_OUTGOING_CALL action. So its ok that your application gets called on getting particular event but if somewhere your application stops for a pop up application the other application (default telephonic application) makes the call as telphonic appication also gets notified as we are just leaving it sdk to call application. Now sdk notifies all the applicaitons that are registered. Jun 20, 2011 at 3:07
  • Sort of. This is an "ordered" broadcast, though, meaning that it get's processed by the registered receivers one at a time. The "default telephonic" application only gets to process it once I am done with it. I could sit in onReceive for ever and the call would never go out. I just can't figure out a way to sit in onReceive while waiting for user input, which is what needs to happen. Again, look at BroadcastReceiver.goAsync for a new method that solves this exact problem in API level 11.
    – Scot
    Jun 20, 2011 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.