IntentService not getting Intents from manifest registration

社会主义新天地 提交于 2019-12-11 09:33:03

问题


This IntentService (NotificationService in the snippet) isn't getting started and doesn't receive those Intents. By registering a receiver for them in the Application class, I've verified that those Intents are being broadcast. I just want to get them when the app isn't started.

    <service
        android:name=".services.NotificationService">
        <intent-filter>
            <action android:name="com.redactedtoprotecttheinnocent.ACTION_INCOMING_CALL"/>
            <action android:name="com.redactedtoprotecttheinnocent.ACTION_CALL_STATUS_CHANGE"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </service>

Any suggestions for what might be wrong here? I'd rather not create a broadcast receiver just to start an IntentService.


回答1:


Any suggestions for what might be wrong here?

You appear to be thinking that services are started automatically by broadcast Intents, which is not the case.

I'd rather not create a broadcast receiver just to start an IntentService.

Well, you are welcome to rewrite the code that is sending com.redactedtoprotecttheinnocent.ACTION_INCOMING_CALL and com.redactedtoprotecttheinnocent.ACTION_CALL_STATUS_CHANGE broadcasts, so that they stop sending broadcasts, and instead use startService() to send commands to your service. If this code is not yours, though, changing it may be difficult.

Or, you can have a short manifest-registered BroadcastReceiver that turns around and calls startService() to have the service process the broadcasts.



来源:https://stackoverflow.com/questions/23225897/intentservice-not-getting-intents-from-manifest-registration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!