Mobile SDK Android: EPZIntentService

From ePrize Developers Wiki

(Difference between revisions)
Jump to: navigation, search

Revision as of 23:04, 6 November 2014

Contents

Overview

The EPZIntentService class extends IntentService. When a notification is received from HelloWorld, this class is set to automatically fetch the full notification data from the HelloWorld servers via the EPZPushNotificationService's fetchNotificationData() method, and will build a Notification to display to the user's device.


Extending EPZIntentService

As noted in the EPZBroadcastReceiver documentation, if you would like to use your own Broadcast Receiver rather than the EPZBroadcastReceiver, you can simply extend it and override its onReceive method. In this case, you will also need to use your own Intent Service class, which should extend EPZIntentService. The code sample below shows how you should extend EPZIntentService.

MyCustomIntentService.java

public class MyCustomIntentService extends EPZIntentService {

    public MyCustomIntentService() {
        super();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        super.onHandleIntent(intent);
    }

    @Override
    public void onNotificationDataRetrieved(Context context, Intent intent, Map<Object, Object> data) {
	
        // Note: Calling 'super' will cause the default Notification to be built. 
        // If you intend to create your own Notification, DO NOT call 'super'.
        super.onNotificationDataRetrieved(context, intent, data);
	
        // Perform any additional actions related to notification data here. For example, you can 
        // save payload IDs of received notifications to your shared preferences.
        // The following code shows how to get the payload ID of a notification.
        String payloadId = data.get(EPZConstants.PUSH_KEY_REMOTE_PAYLOAD).toString();
	
    }

}


Public Methods

onHandleIntent

@Override
protected void onHandleIntent(Intent intent)

Override method of IntentService, called when the IntentService is invoked to process a request.

This method includes all necessary logic to get the initial notification data, which it passes to the onNotificationDataReceived method where a notification is built.


Parameters
intent The Intent being received.



onNotificationDataRetrieved

public void onNotificationDataRetrieved(Context context, Intent intent, Map<Object, Object> data)

Method called when a message's full notification data has been retrieved from the HelloWorld servers. This method may be overridden if desired, though if you intend to build your own Notification, you will not want to call the super method when doing so, as the default implementation builds a Notification.

Notes on the default Notification built:

  • The SDK's default notification icon is used for the small icon (R.drawable.epz_stat_notify_msg) unless otherwise specified in the options passed in to the configure method of the EPZPushNotificationService.
  • The parent app's name is used as the content title.
  • The "alert" value from the 'data' parameter is used for the content text.
  • A PendingIntent is created, using the "className" value from the 'data' parameter (if found from the initial GCM message or the full notification payload). If no "className" is found, the PendingIntent defaults to the parent app's launch intent.
  • For convenience, all key/value pairs from the 'data' parameter are added to the extras of the PendingIntent, so they are available if needed.
  • All notifications generated by this method use the same "id" value and do not set the "number" property on the notification. As such, the newest notification will override any existing notifications. If you would like to set the "number" property, it is your responsibility and you will need to override this method.


Parameters
context The Context in which the receiver is running.

intent The Intent being received.

data The full data Map associated with notification. At the very least, this value will include the keys listed below. (Note: If no value is found for any of these keys, a blank string is used.)

  • alert (used for the Notification content text)
  • className (used in creating the PendingIntent, if not blank)
  • content (specifies the full content of the notification message)
  • remotePayloadId (used to retrieve the full notification data)
  • type (used to specify the type of notification message)
Personal tools