com.parse
Class ParsePushBroadcastReceiver

Object
  extended by android.content.BroadcastReceiver
      extended by com.parse.ParsePushBroadcastReceiver

public class ParsePushBroadcastReceiver
extends BroadcastReceiver

A BroadcastReceiver for rendering and reacting to to Notifications. This BroadcastReceiver must be registered in order to use the ParsePush subscription methods. As a security precaution, the intent filters for this BroadcastReceiver must not be exported. Add the following lines to your AndroidManifest.xml file, inside the <application> element to properly register the ParsePushBroadcastReceiver:

 <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported=false>
  <intent-filter>
     <action android:name="com.parse.push.intent.RECEIVE" />
     <action android:name="com.parse.push.intent.OPEN" />
     <action android:name="com.parse.push.intent.DELETE" />
   </intent-filter>
 </receiver>
 
The ParsePushBroadcastReceiver is designed to provide maximal configurability with minimal effort. To customize the push icon, add the following line as a child of your <application> element:
   <meta-data android:name="com.parse.push.notification_icon"
              android:resource="@drawable/icon"/>
 
where drawable/icon may be the path to any drawable resource. The Android style guide for Notifications suggests that push icons should be flat monochromatic images.

To achieve further customization, ParsePushBroadcastReceiver can be subclassed. When providing your own implementation of ParsePushBroadcastReceiver, be sure to change com.parse.PushBroadcastReceiver to the name of your custom subclass in your AndroidManifest.xml. You can intercept and override the behavior of entire portions of the push lifecycle by overriding ParsePushBroadcastReceiver.onPushReceive(Context, Intent), ParsePushBroadcastReceiver.onPushOpen(Context, Intent), or ParsePushBroadcastReceiver.onPushDismiss(Context, Intent). To make minor changes to the appearance of a notification, override ParsePushBroadcastReceiver.getSmallIconId(Context, Intent) or ParsePushBroadcastReceiver.getLargeIcon(Context, Intent). To completely change the Notification generated, override ParsePushBroadcastReceiver.getNotification(Context, Intent). To change the Activity launched when a user opens a Notification, override ParsePushBroadcastReceiver.getActivity(Context, Intent).


Nested Class Summary
 
Nested classes/interfaces inherited from class android.content.BroadcastReceiver
BroadcastReceiver.PendingResult
 
Field Summary
static String ACTION_PUSH_DELETE
          The name of the Intent fired when a notification has been dismissed.
static String ACTION_PUSH_OPEN
          The name of the Intent fired when a notification has been opened.
static String ACTION_PUSH_RECEIVE
          The name of the Intent fired when a push has been received.
static String KEY_PUSH_CHANNEL
          The name of the Intent extra which contains a channel used to route this notification.
static String KEY_PUSH_DATA
          The name of the Intent extra which contains the JSON payload of the Notification.
static String PROPERTY_PUSH_ICON
          The name of the meta-data field used to override the icon used in Notifications.
protected static int SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT
           
 
Constructor Summary
ParsePushBroadcastReceiver()
           
 
Method Summary
protected  Class<? extends Activity> getActivity(Context context, Intent intent)
          Used by onPushOpen to determine which activity to launch or insert into the back stack.
protected  Bitmap getLargeIcon(Context context, Intent intent)
          Retrieves the large icon to be used in a Notification.
protected  Notification getNotification(Context context, Intent intent)
          Creates a Notification with reasonable defaults.
protected  int getSmallIconId(Context context, Intent intent)
          Retrieves the small icon to be used in a Notification.
protected  void onPushDismiss(Context context, Intent intent)
          Called when the push notification is dismissed.
protected  void onPushOpen(Context context, Intent intent)
          Called when the push notification is opened by the user.
protected  void onPushReceive(Context context, Intent intent)
          Called when the push notification is received.
 void onReceive(Context context, Intent intent)
          Delegates the generic onReceive event to a notification lifecycle event.
 
Methods inherited from class android.content.BroadcastReceiver
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_PUSH_CHANNEL

public static final String KEY_PUSH_CHANNEL
The name of the Intent extra which contains a channel used to route this notification. May be null.

See Also:
Constant Field Values

KEY_PUSH_DATA

public static final String KEY_PUSH_DATA
The name of the Intent extra which contains the JSON payload of the Notification.

See Also:
Constant Field Values

ACTION_PUSH_RECEIVE

public static final String ACTION_PUSH_RECEIVE
The name of the Intent fired when a push has been received.

See Also:
Constant Field Values

ACTION_PUSH_OPEN

public static final String ACTION_PUSH_OPEN
The name of the Intent fired when a notification has been opened.

See Also:
Constant Field Values

ACTION_PUSH_DELETE

public static final String ACTION_PUSH_DELETE
The name of the Intent fired when a notification has been dismissed.

See Also:
Constant Field Values

PROPERTY_PUSH_ICON

public static final String PROPERTY_PUSH_ICON
The name of the meta-data field used to override the icon used in Notifications.

See Also:
Constant Field Values

SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT

protected static final int SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT
See Also:
Constant Field Values
Constructor Detail

ParsePushBroadcastReceiver

public ParsePushBroadcastReceiver()
Method Detail

onReceive

public void onReceive(Context context,
                      Intent intent)
Delegates the generic onReceive event to a notification lifecycle event. Subclasses are advised to override the lifecycle events and not this method.

Specified by:
onReceive in class BroadcastReceiver
Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.
See Also:
ParsePushBroadcastReceiver.onPushReceive(Context, Intent), ParsePushBroadcastReceiver.onPushOpen(Context, Intent), ParsePushBroadcastReceiver.onPushDismiss(Context, Intent)

onPushReceive

protected void onPushReceive(Context context,
                             Intent intent)
Called when the push notification is received. By default, a broadcast intent will be sent if an "action" is present in the data and a notification will be show if "alert" and "title" are present in the data.

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.

onPushDismiss

protected void onPushDismiss(Context context,
                             Intent intent)
Called when the push notification is dismissed. By default, nothing is performed on notification dismissal.

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.

onPushOpen

protected void onPushOpen(Context context,
                          Intent intent)
Called when the push notification is opened by the user. Sends analytics info back to Parse that the application was opened from this push notification. By default, this will navigate to the Activity returned by ParsePushBroadcastReceiver.getActivity(Context, Intent). If the push contains a 'uri' parameter, an Intent is fired to view that URI with the Activity returned by getActivity() in the back stack.

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.

getActivity

protected Class<? extends Activity> getActivity(Context context,
                                                Intent intent)
Used by onPushOpen to determine which activity to launch or insert into the back stack. The default implementation retrieves the launch activity class for the package. Returns null if no launch intent is defined in AndroidManifest.xml

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.
Returns:
The default activity class of the package

getSmallIconId

protected int getSmallIconId(Context context,
                             Intent intent)
Retrieves the small icon to be used in a Notification. The default implementation uses the icon specified in the "com.parse.push.notification_icon" manifest meta-data with a fallback to the launcher icon for this package. To conform to Android style guides, it is highly recommended that developers specify an explicit push icon.

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.
Returns:
The resource id of the default small icon for the package
See Also:
Android Notification Style Guide

getLargeIcon

protected Bitmap getLargeIcon(Context context,
                              Intent intent)
Retrieves the large icon to be used in a Notification. This bitmap should be used to provide special context for a particular notification, such as the avatar of user who generated the Notification. The default implementation returns null, causing the Notification to display only the small icon.

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.
Returns:
Bitmap of the default large icon for the package
See Also:
Android Notification UI Overview

getNotification

protected Notification getNotification(Context context,
                                       Intent intent)
Creates a Notification with reasonable defaults. If "alert" and "title" are both missing from data, then returns null. If the text in the notification is longer than 38 characters long, the style of the notification will be set to BigTextStyle. As a security precaution, developers overriding this method should be sure to set the package on notification Intents to avoid leaking information to other apps.

Parameters:
context - The Context in which the receiver is running.
intent - An Intent containing the channel and data of the current push notification.
Returns:
The notification to be displayed.
See Also:
ParsePushBroadcastReceiver.onPushReceive(Context, Intent)