Asbjorn Sondergaard avatar image
Asbjorn Sondergaard asked

Receiving ADM messages while app is running

Hi, We would like to intercept ADM messages when our app is in the foreground. Our current approach is the following: In our activity we do the following: private BroadcastReceiver _onPushMessage = new ADMRuntimePushReceiver(); @Override public void onResume() { //Create intent filter for intercepting push message in-app when running. IntentFilter filter = new IntentFilter(; filter.addCategory(this.getPackageName()); //Give higher priority to ensure we see message before background service filter.setPriority(2); //Register the receiver for push messages this.registerReceiver(_onPushMessage, filter); } @Override protected void onPause() { //Unregister the receiver for push messages when paused this.unregisterReceiver(_onPushMessage); } The ADMRuntimePushReceiver looks like the following: public class ADMRuntimePushReceiver extends BroadcastReceiver { private static final String TAG = "dk.tactile.adm.ADMRuntimePushReceiver"; @Override public final void onReceive(Context context, Intent intent) { Log.i(TAG, "Received push message while running"); //Ensure that our background service activity does not process the message. abortBroadcast(); } } Unfortunately this approach does not work. The registered ADMMessageHandler service always receives the ADM message and our runtime registered receiver never receives anything. Our manifest entries related to ADM looks like the following: Does anybody have any idea about why we are not able to successfully intercept the ADM messages with our dynamically registered broadcast receiver at runtime? Best regards, Morten
amazon device messaging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Asbjorn, Thank you for writing to us. There is a sample app that is shipped with ADM SDK and there we had a similar example of using dynamically registered broadcast receiver and that works perfectly fine. So we broadcast message from onMessage of base class of ADMMessageHandlerBase and the receiver which is registered in onResume (like yours), receives the message and update the UI to display the received message. I even tested that with the intent and category like yours and that also worked. Please check out the sample app.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.