BroadcastReceiver的不接受意向 [英] BroadcastReceiver not receiving intent

查看:110
本文介绍了BroadcastReceiver的不接受意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,现在我已经在manifest文件中声明我BroastcastReceiver ...

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>

我要赶的意图时,呼叫按钮是pressed。

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

下面是我的code ...

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...

<一个href="http://stackoverflow.com/questions/1909812/how-to-use-intents-from-a-service-or-broadcast-receiver">http://stackoverflow.com/questions/1909812/how-to-use-intents-from-a-service-or-broadcast-receiver

推荐答案

简短的回答是,你不能做你想要做的事情。

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

的'ACTION_CALL_BUTTON'动作是活动开始行动,而不是广播动作。它可以用在 startActivity 用一个Intent来启动,应该呼叫按钮时pressed响应的活动。你想要的是,当呼叫按钮是pressed得到通知,并且系统不广播意图宣布。

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.

另外,也可以包括相同的意图过滤器上的活动把它拿出为用户提供一个选项,当他们preSS调用选择按钮。

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.

什么是你希望做,当用户presses呼叫按钮?

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

这篇关于BroadcastReceiver的不接受意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆