public class ParsePushBroadcastReceiver extends BroadcastReceiver
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).
BroadcastReceiver.PendingResult| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
ParsePushBroadcastReceiver() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtraspublic static final String KEY_PUSH_CHANNEL
public static final String KEY_PUSH_DATA
public static final String ACTION_PUSH_RECEIVE
public static final String ACTION_PUSH_OPEN
public static final String ACTION_PUSH_DELETE
public static final String PROPERTY_PUSH_ICON
protected static final int SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT
public void onReceive(Context context, Intent intent)
onReceive in class BroadcastReceivercontext - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.ParsePushBroadcastReceiver.onPushReceive(Context, Intent),
ParsePushBroadcastReceiver.onPushOpen(Context, Intent),
ParsePushBroadcastReceiver.onPushDismiss(Context, Intent)protected void onPushReceive(Context context, Intent intent)
context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected void onPushDismiss(Context context, Intent intent)
context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected void onPushOpen(Context context, Intent intent)
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.context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected Class<? extends Activity> getActivity(Context context, Intent intent)
context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected int getSmallIconId(Context context, Intent intent)
context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected Bitmap getLargeIcon(Context context, Intent intent)
context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected Notification getNotification(Context context, Intent intent)
context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.ParsePushBroadcastReceiver.onPushReceive(Context, Intent)