我需要一些帮助,以了解何时可以期望广播接收器在清单中进行注册后才能正常工作,而不必从正在运行的活动或服务中进行注册。
因此,例如,如果我使用以下意图过滤器注册独立接收器,则该接收器可以在不具有服务/活动引用的情况下运行:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blk_burn.standalonereceiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name="TestReceiver">
<intent-filter>
<action android:name="android.media.AUDIO_BECOMING_NOISY"/>
</intent-filter>
</receiver>
</application>
</manifest>
但是如果我更换android.media.AUDIO_BECOMING_NOISY
与android.intent.action.HEADSET_PLUG
接收器没有被触发(Android文档)
根据我在该站点上发现的信息,您必须从已经运行的一项活动或服务中注册该接收器,以使其正常工作(发布)。
谁能告诉我为什么仅在清单中调整意图过滤器时为什么此方法不起作用,以及为什么需要在后台运行一个引用/注册接收器的服务?
有没有变通的方法,这样我就可以使用intent过滤器在我的应用清单中注册接收者了
android.intent.action.HEADSET_PLUG
?我该如何确定android文档中的哪些Broadcast操作需要服务或活动进行注册,而不是在清单中添加正确的过滤器?