1

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" >
   <intent-filter>
     <action android:name="android.intent.action.FENCE_RECEIVER_ACTION" />
    </intent-filter>
</receiver>

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?

Community
  • 1
  • 1
Ziv Kesten
  • 1,206
  • 25
  • 41

1 Answers1

5

Ok so the answer eventually was that you have to register this receiver in the manifest 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.

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.

Ziv Kesten
  • 1,206
  • 25
  • 41
  • 1
    Used your method. Works when the app is in the foreground, and also works when i press the home button and the app is no longer in the foreground. However, when i close the app from the recent app list, it no longer works. Any ideas how to get it to still work when the app is closed? i.e the trigger launches the app or something? – Ayo Makanjuola Mar 07 '17 at 21:37
  • @AyoMakanjuola, did you figure out how to do it? – Emre Akcan Jul 03 '20 at 16:33