If you want to have your BroadcastReceivers
triggered regardless of your apps state then you should register them through your applications AndroidManifest.xml
file.
Heres how to do it.
Define a class that extends
BroadcastReceiver
and implement theonReceive()
method. I see that you have already done that -ProximityIntentReceiver
is that class.In your AndroidManifest.xml file add:
<application> ... <receiver android:name=".MyReceiver" android:exported="false" > <intent-filter> <action android:name="my.app.ACTION" /> </intent-filter> </receiver> </application>
Where MyReceiver
is the name of your receiver class (ProximityIntentReceiver
in your case) and my.app.ACTION is the action that your receiver will listen for (in your case I'm guessing it's the value of PROX_ALERT_INTENT_ID
).
Note: Saying that the name of your receiver is .MyReceiver
assumes that it's located in the root package of your app. If that is not the case then you need to provide the path to that class starting from the root.