Android的接收器,多个操作? [英] Android receiver for multiple actions?

查看:126
本文介绍了Android的接收器,多个操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题 - 我可以注册一个的BroadcastReceiver 以多意图的行动?下面是我在考虑:

Simple question - can I register a single BroadcastReceiver to multiple intent actions? Here's what I'm considering:

<receiver android:name=".myReceiver">
    <intent-filter android:priority="1000000">
        <action android:name="android.intent.action.MEDIA_BUTTON" />
        <action android:name="android.intent.action.ACTION_HEADSET_PLUG" />
    </intent-filter>
</receiver>

因此​​,在 myReceiver 的onReceive ,可能我检查 intent.getAction() ACTION_MEDIA_BUTTON和ACTION_HEADSET_PLUG

So in myReceiver class' onReceive, could I check intent.getAction() for both ACTION_MEDIA_BUTTON and ACTION_HEADSET_PLUG?

感谢。

推荐答案

我想你可以有多个S每一个有它的动作元素。

I guess you can have multiple s each one having its action element.

<receiver android:name=".myReceiver">
     <intent-filter android:priority="1000000">
         <action android:name="android.intent.action.ACTION_HEADSET_PLUG" />
     </intent-filter>

     <intent-filter android:priority="1000000">
         <action android:name="android.intent.action.MEDIA_BUTTON" />
     </intent-filter>
</receiver>

然后检查意向的行动,在接收器的onReceive。

And then check the Intent's action in the onReceive of the receiver.

这篇关于Android的接收器,多个操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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