Restrict Broadcast Receiver to application

余生长醉 提交于 2019-12-01 10:35:22

What you are talking is not possible. The whole purpose of having the intent filter in the manifest is being able to receive the intent whether or not your application is running. The only way to do what you want to is by registering/unregistering the receiver from the code [registerReceiver]

You said "My problem will solve if it is not receiving anything when application is not opened".

Here how I understand your question and appropriate answer.

android:enabled

Whether or not the broadcast receiver can be instantiated by the system — "true" if it can be, and "false" if not. The default value is "true".

If you want to enable your receiver at runtime, you can set the state to disabled initially. You can do so in the manifest file:

<receiver
android:name=".YourReceiver"
android:enabled="false" >
<!-- your intent filter -->
</receiver>

Source: http://developer.android.com/guide/topics/manifest/receiver-element.html#enabled

http://www.grokkingandroid.com/enabling-and-disabling-broadcastreceivers/

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