i am implementing the google Awareness API in an android app, but none of the samples, nor the guides, shows how to listen to the api events while the app is down or in the background.
I wrote a global receiver based on the answer here
<receiver android:name=".MyFenceReceiver" >
<action android:name="android.intent.action.FENCE_RECEIVER_ACTION" />
Ok so the answer eventually was that you have to register this receiver in code and give it your own intent filter like this:
Intent intent = new Intent(Constants.Requests.FENCE_RECEIVER_ACTION); mPendingIntent = PendingIntent.getBroadcast(BaseActivity.this, 0, intent, 0); // The broadcast receiver that will receive intents when a fence is triggered. registerReceiver(new FenceReceiver(), new IntentFilter(FENCE_RECEIVER_ACTION));
where "FENCE_RECEIVER_ACTION" is this:
// The intent action which will be fired when your fence is triggered. public final static String FENCE_RECEIVER_ACTION = BuildConfig.APPLICATION_ID + "FENCE_RECEIVER_ACTION";
And in the manifest you put in the receiver like this:
<receiver android:name=".FenceReceiver" > <intent-filter> <action android:name="'YOUR_PACKGE_NAME_HERE'FENCE_RECEIVER_ACTION" /> </intent-filter> </receiver>
There is no need to unregister the receiver anywhere.