Android Push Notifications

This tutorial provides you with a step-by-step guide to configuring your Android application for push.

Push Notifications

Push notifications let your application notify a user of new messages or events even when the user is not actively using your application. On Android devices, when a device receives a push notification, your application's icon and a message appear in the status bar. When the user taps the notification, they are sent to your application. Notifications can be broadcast to all users, such as for a marketing campaign, or sent to just a subset of users, to give personalized information.

The Parse library provides push notifications by using Google Cloud Messaging (GCM).

1. Connect your app to Parse

Before getting started, you will need to set up and connect your app to Parse. Follow the steps laid out in our Android Push Notifications Quick Start guide, then continue with step 2.

2. Send a Test Push Notification

At this point, you're ready to send push notifications. Unlike iOS, Android push notifications do work from the emulator, so you can use the emulator to test out push.

Push Notifications tab

In your Parse dashboard, select the app you want to use to send pushes. Next, navigate to the "Push Notifications" section. From here, you can see all the pushes you've recently sent. To compose a new one, we'll select the "Send a push" button.

From here, you can configure all you'll need to send your push notification. You can use the provided text box to send push notifications to all of your app's users.

For more information on Push Notifications in Android, take a look at our Push Guide.

3. Customizing Notifications

Now that your app is all set up to receive push notifications, you can start customizing the display of these notifications. This is only a subset of the things you can do; please refer to the Android Push Notifications Guide for more details.

Choose Your Push Icon

The Android style guide recommends apps use a push icon that is monochromatic and flat. The default push icon is your application's launcher icon, which is unlikely to conform to the style guide. To provide a custom push icon, add the following metadata tag to your app's AndroidManifest.xml, immediately before the closing </application> tag:

<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/push_icon"/>

...where push_icon is the name of a drawable resource in your package. If your application needs more than one small icon, you can override getSmallIconId in your ParsePushBroadcastReceiver subclass.

If your push has a unique context associated with an image, such as the avatar of the user who sent a message, you can use a large push icon to call attention to the notification. When a notification has a large push icon, your app's static (small) push icon is moved to the lower right corner of the notification and the large icon takes its place. See the Android UI documentation for examples. To provide a large icon, you can override getLargeIcon in your ParsePushBroadcastReceiver subclass.

Responding with a Custom Activity

If your push has no "uri" parameter, onPushOpen will invoke your application's launcher activity. To customize this behavior, you can override getActivity in your ParsePushBroadcastReceiver subclass.

Responding with a URI

If you provide a "uri" field in your push, the ParsePushBroadcastReceiver will open that URI when the notification is opened. If there are multiple apps capable of opening the URI, a dialog will displayed for the user. The ParsePushBroadcastReceiver will manage your back stack and ensure that clicking back from the Activity handling URI will navigate the user back to the activity returned by getActivity.

Troubleshooting Push Notifications

Setting up Push Notifications is often a source of frustration for developers. The process is complicated and invites problems to happen along the way. If you run into issues, try some of these troubleshooting tips.