Mobile SDK Android: EPZBroadcastReceiver
From ePrize Developers Wiki
Contents |
Overview
The EPZBroadcastReceiver class extends WakefulBroadcastReceiver, and handles receiving messages from Google Cloud Messaging for push notifications, and includes all necessary logic to receive and handle a notification. This class can easily be extended for greater flexibility and customization for your application.
Extending EPZBroadcastReceiver
If you would like to use your own Broadcast Receiver rather than the EPZBroadcastReceiver, you can simply extend EPZBroadcastReceiver and override the onReceive method as seen in the code sample below. Note that you will also need to use your own Intent Service class, which should extend EPZIntentService.
MyCustomBroadcastReceiver.java
public class MyCustomBroadcastReceiver extends EPZBroadcastReceiver { private final EPZPushNotificationService mPushService = EPZPushNotificationService.getInstance(); @Override public void onReceive(Context context, Intent intent) { // Set EPZPushNotificationService context mPushService.setAppContext(context); // Explicitly specify that *OUR OWN* Intent Service class will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), MyCustomIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); } }
Public Methods
onReceive
@Override public void onReceive(Context context, Intent intent)
Override method of BroadcastReceiver, called when the BroadcastReceiver is receiving an Intent broadcast.
This method includes a conditional check for the message type to determine if the message is one from HelloWorld, and if so, will automatically attempt to fetch the full payload of message notification data.
Parameters
context The Context in which the receiver is running.
intent The Intent being received.