views:

407

answers:

2

So now I have my BroastcastReceiver declared in the manifest file...

   <receiver android:name=".MyReceiver">
    <intent-filter>
     <action android:name="android.intent.action.CALL_BUTTON" />
    </intent-filter>
   </receiver>

I want to catch the intent when the Call button is pressed.

Here is my code...

 public class MyReceiver extends BroadcastReceiver {

     @Override
     public void onReceive(Context context, Intent intent) {

      Toast.makeText(context, "intent received", Toast.LENGTH_LONG);

      if(intent.getAction().equals("android.intent.action.CALL_BUTTON")) {
       Toast.makeText(context, "call button pressed", Toast.LENGTH_LONG);
      }

     }

 }

However, I don't see the toast when I hit the call button. Did I miss something?

This is a continuation using an answer from this question...

http://stackoverflow.com/questions/1909812/how-to-use-intents-from-a-service-or-broadcast-receiver

+1  A: 

Per the docs, ACTION_CALL_BUTTON is not a broadcast action; rather, it's an activity action.

See Dianne's message about this in another thread.

Roman Nurik
Thanks. So is there no way to launch my activity when a user presses the Call button?
Eclipsed4utoo
Sorry I didn't elaborate further. Reto's got it covered :-)
Roman Nurik
+2  A: 

The short answer is that you can't do what you're trying to do.

The 'ACTION_CALL_BUTTON' action is an "Activity starting action" rather than a "Broadcast action". It can be used in an Intent used in startActivity to launch an Activity that should respond to the call button being pressed. What you want is to be notified when the call button is pressed, and the system doesn't broadcast an Intent to announce that.

Alternatively, you could include the same intent-filter on an Activity to have it come up as an option for the user to select when they press the call button.

What are you hoping to do when the user presses the call button?

Reto Meier
Once again, you have come to the rescue. That is exactly what I wanted to do in the first place....open an activity when the call button is pressed.
Eclipsed4utoo