简单的问题-我可以将一个广播接收器注册到多个意图操作吗?我在考虑的是:
<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 and ACTION_HEADSET_PLUG
吗?谢谢。
最佳答案
我想你可以有多个,每个都有它的动作元素。
<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中检查意图的动作。