public class ParsePushBroadcastReceiver
extends android.content.BroadcastReceiver
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 onPushReceive(Context, Intent),
onPushOpen(Context, Intent), or onPushDismiss(Context, Intent).
To make minor changes to the appearance of a notification, override
getSmallIconId(Context, Intent) or getLargeIcon(Context, Intent). To completely
change the Notification generated, override getNotification(Context, Intent). To
change the NotificationChannel generated, override getNotificationChannel(Context, Intent). To
change how the NotificationChannel is created, override createNotificationChannel(Context, NotificationChannel).
To change the Activity launched when a user opens a Notification, override
getActivity(Context, Intent).| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACTION_PUSH_DELETE
The name of the Intent fired when a notification has been dismissed.
|
static java.lang.String |
ACTION_PUSH_OPEN
The name of the Intent fired when a notification has been opened.
|
static java.lang.String |
ACTION_PUSH_RECEIVE
The name of the Intent fired when a push has been received.
|
static java.lang.String |
KEY_PUSH_CHANNEL
The name of the Intent extra which contains a channel used to route this notification.
|
static java.lang.String |
KEY_PUSH_DATA
The name of the Intent extra which contains the JSON payload of the Notification.
|
static java.lang.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 void |
createNotificationChannel(android.content.Context context,
android.app.NotificationChannel notificationChannel)
Creates the notification channel with the NotificationManager.
|
protected java.lang.Class<? extends android.app.Activity> |
getActivity(android.content.Context context,
android.content.Intent intent)
Used by
onPushOpen(android.content.Context, android.content.Intent) to determine which activity to launch or insert into the back
stack. |
protected android.content.Intent |
getContentIntent(android.os.Bundle extras,
java.lang.String packageName)
Get the content intent, which is the intent called when a notification is tapped.
|
protected android.content.Intent |
getDeleteIntent(android.os.Bundle extras,
java.lang.String packageName)
Get the delete intent, which is the intent called when a notification is deleted (swiped away).
|
protected android.graphics.Bitmap |
getLargeIcon(android.content.Context context,
android.content.Intent intent)
Retrieves the large icon to be used in a
Notification. |
protected NotificationCompat.Builder |
getNotification(android.content.Context context,
android.content.Intent intent)
Creates a
Notification with reasonable defaults. |
protected android.app.NotificationChannel |
getNotificationChannel(android.content.Context context,
android.content.Intent intent)
Retrieves the channel to be used in a
Notification if API >= 26, if not null. |
protected org.json.JSONObject |
getPushData(android.content.Intent intent)
Get the push data as a parsed JSONObject
|
protected int |
getSmallIconId(android.content.Context context,
android.content.Intent intent)
Retrieves the small icon to be used in a
Notification. |
protected void |
onPushDismiss(android.content.Context context,
android.content.Intent intent)
Called when the push notification is dismissed.
|
protected void |
onPushOpen(android.content.Context context,
android.content.Intent intent)
Called when the push notification is opened by the user.
|
protected void |
onPushReceive(android.content.Context context,
android.content.Intent intent)
Called when the push notification is received.
|
void |
onReceive(android.content.Context context,
android.content.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 java.lang.String KEY_PUSH_CHANNEL
null.public static final java.lang.String KEY_PUSH_DATA
public static final java.lang.String ACTION_PUSH_RECEIVE
public static final java.lang.String ACTION_PUSH_OPEN
public static final java.lang.String ACTION_PUSH_DELETE
public static final java.lang.String PROPERTY_PUSH_ICON
protected static final int SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT
public void onReceive(android.content.Context context,
android.content.Intent intent)
onReceive event to a notification lifecycle event.
Subclasses are advised to override the lifecycle events and not this method.onReceive in class android.content.BroadcastReceivercontext - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.onPushReceive(Context, Intent),
onPushOpen(Context, Intent),
onPushDismiss(Context, Intent)protected void onPushReceive(android.content.Context context,
android.content.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(android.content.Context context,
android.content.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(android.content.Context context,
android.content.Intent intent)
Activity returned by getActivity(Context, Intent). If the push contains
a 'uri' parameter, an Intent is fired to view that URI with the Activity returned by
getActivity(android.content.Context, android.content.Intent) 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 java.lang.Class<? extends android.app.Activity> getActivity(android.content.Context context,
android.content.Intent intent)
onPushOpen(android.content.Context, android.content.Intent) to determine which activity to launch or insert into the back
stack. The default implementation retrieves the launch activity class for the package.context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.Activity class of the package or null if no launch intent is
defined in AndroidManifest.xml.protected android.app.NotificationChannel getNotificationChannel(android.content.Context context,
android.content.Intent intent)
Notification if API >= 26, if not null. The default returns a new channel
with id "parse_push", name "Push notifications" and default importance.context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected void createNotificationChannel(android.content.Context context,
android.app.NotificationChannel notificationChannel)
context - The Context in which the receiver is running.notificationChannel - The NotificationChannel to be created.protected int getSmallIconId(android.content.Context context,
android.content.Intent intent)
Notification. The default implementation uses
the icon specified by com.parse.push.notification_icon meta-data in your
AndroidManifest.xml 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.context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected android.graphics.Bitmap getLargeIcon(android.content.Context context,
android.content.Intent intent)
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.context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.protected org.json.JSONObject getPushData(android.content.Intent intent)
intent - the intent of the notificationprotected android.content.Intent getContentIntent(android.os.Bundle extras,
java.lang.String packageName)
ACTION_PUSH_OPEN in order
to still trigger onPushOpen(Context, Intent)extras - the extraspackageName - the app package nameprotected android.content.Intent getDeleteIntent(android.os.Bundle extras,
java.lang.String packageName)
ACTION_PUSH_DELETE in order
to still trigger onPushOpen(Context, Intent)extras - the extraspackageName - the app package nameprotected NotificationCompat.Builder getNotification(android.content.Context context,
android.content.Intent intent)
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
Notification.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.context - The Context in which the receiver is running.intent - An Intent containing the channel and data of the current push notification.onPushReceive(Context, Intent)