public class ParsePushBroadcastReceiver extends 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 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
ParsePushBroadcastReceiver.onPushOpen(android.content.Context, android.content.Intent) 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, setResultExtras
public static final String KEY_PUSH_CHANNEL
null
.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
event to a notification lifecycle event.
Subclasses are advised to override the lifecycle events and not this method.onReceive
in class BroadcastReceiver
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)
,
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)
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
ParsePushBroadcastReceiver.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 Class<? extends Activity> getActivity(Context context, Intent intent)
ParsePushBroadcastReceiver.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 int getSmallIconId(Context context, 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 Bitmap getLargeIcon(Context context, 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 Notification getNotification(Context context, 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 Intent
s 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.ParsePushBroadcastReceiver.onPushReceive(Context, Intent)