parse_feature_image

Push Notification in Android using Parse SDK


In the last tutorial, i explained how to use GCM service in Android. In this tutorial i’ll explain the same Push Notification service using Parse SDK.

 

What is Parse SDK ?

Parse is a cloud-based data management system that allows you to quickly develop web and mobile apps.

It makes developing apps really easy by taking the back-end out of your hands.

Parse is one of the more popular Backend as a Service platforms. The service offers three products in one package:

  1. Parse Core generally handles the saving of data and social media integration.
  2. Parse Push is used to send push notifications. It enables the developer to customize, schedule and send push notifications to either all registered users or a select group of users.
  3. Parse Analytic enables you to track your app’s data. You can track usage data such as installations, active users, user retention, push notification open rate etc.

 

Why Parse SDK ?

  • The primary advantages of Parse are that you’ll be able to work with application-level concepts like user accounts and push notifications rather than technology-focused concepts like databases and socket I/O.
  • Parse helps to share native models across server-side code and multiple clients.
  • It’s mainly for front-end mobile (iOS, Android etc) developers who have little backend skills or resources but need some simple backend for their mobile app.

If we speak about why parse sdk, then the whole day will not be enough so lets get back to work. In this tutorial, we’ll look at only Parse Push concept.

 

Prerequisites:

  1. Go to Parse.com and sign up.
  2. On your dashboard, Create new App and enter details for your app.
    parse_dashboard
    push_app
  3. Once your App is created, you’ll land up in key sections, where you need to copy both Application ID & Client Key which you required for Android Application.
  4. On Android Studio, build.gradle use: compile 'com.parse:parse-android:1.10.2'

Now you can follow, the tutorial provided by Parse.com or go a head to read mine.

 

In order to make parse work, parse need to initialize at Application onCreate rather than at Activity onCreate. So copy this code on your class which extends Application.

In the App Manifest, Add the following service and broadcast receiver definitions to the Manifest:

Also add the permissions below to the Manifest :

That’s it no extra code to test a simple push notification on your device.

 

Send a Test Push Notification:

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.

new push

push_recipients

push_plaintext

parse_pushnotification_text

push_test

Customizing Push Notification using Custom Receiver:

Parse comes with a default broadcast push receiver, but the options are limited. If you want to fully utilize the parse notifications, the best option is create a custom receiver.

Create a class named CustomPushReceiver.java which extends ParsePushBroadcastReceiver which callbacks methods are:

onPushReceive() – method will be called whenever push message is received. In this message the json message will be parsed and shown to user.

onPushDismiss() – method will be called whenever push message is dismissed from the status bar.

onPushOpen() – method will be called whenever push message is selected by the user.

Add the following broadcast receiver definitions to AndroidManifest.xml immediately before the closing</application> tag:

 

To provide a custom push icon, add the following metadata tag to your app’s AndroidManifest.xml, immediately before the closing </application> tag:

For more Customizing, you can create your own push notification using NotificationCompact Builder at onPushReceive() method.

 

Since we are customizing, simple plain text will not be so effective, so we need enter message as a Json data in parse.com. Go to “Push” section, select “Send a Push” option and change message to Json.

push_custom_message

parse_pushnotification_json

push_analytics

Subscribe to a Topic:

Not only customizing the notification, Parse SDK has one more feature where user can subscribe to one or more topics.

To subscribe a topic, you need to create a new channel and use subscribeInBackground which callback done method.

To unsubscribe a topic, you need to use the channel in unsubscribeInBackground which callback done method.

push_recipients_custom

push_recipients_custom_cannel

parse_pushnotification parse_pushnotification_channel

Complete Source code available here.

References:


About Durga Chiranjeevi

I’m a normal guy, engineer by education who is passionate about Programming and Internet. An android enthusiast, now moving for cross platforms and game development.