Ziv Kesten Ziv Kesten - 1 year ago 143
Android Question

Awareness API global receiver intent filter

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" />

However, since it is not working, i suspect i don't know the correct intent filter for intercepting the Awarness events.
Does anyone know the correct intent filter, or if this is not my issue, how can i intercept the API events while the app is down or in the background with a global receiver?

Answer Source

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 =

And in the manifest you put in the receiver like this:

 <receiver android:name=".FenceReceiver" >
            <action android:name="'YOUR_PACKGE_NAME_HERE'FENCE_RECEIVER_ACTION" />

There is no need to unregister the receiver anywhere.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download