Android Push Notifications

This tutorial will help you configure your Android app to send and receive push notifications. App42 Cloud API provides push notifications using GCM (Google Cloud Messaging). You may then send push notifications from AppHQ console as well as shoot notifications by simply using APIs to your app users. The beauty of App42 Push is that you can schedule notifications and even send location based messages as well. Along with sending push notifications, you can also capture detailed insights of the response your push messages with the analytics. Please follow these easy steps to get started with the App42 platform and start sending push messages within minutes.

1. Prerequisite Setup

Sign up with App42 platform to create your first app after choosing App42 Cloud APIs and Android as your preferred platform

Connect your app with App42 by following the steps mentioned after you download the Android SDK

If you have created your first app already, simply login to AppHQ console to continue

Unzip the downloaded file and import the project in eclipse and add google_play_service as a library

Open MainActivty.java file in which you would have to pass the required information in onCreate and onStart method like API KEY & SECRET KEY which you must have received after the completion of integration steps in AppHQ Console, Logged In User is basically that user for which you want to register your device to push & Google Project No is received after the success of project creation from google developer console in the above steps

The code snippet provided will carry out most of the important work for you conveniently. Once your app gets started, it will register your application with GCM as well as with App42 platform in order to send push notifications. Just to let you know, it uses storeDeviceToken method to register your application with the App42 server. This is just a one time activity and will be done automatically whenever the app is opened.

If you want to know the details about the sample code, please go through App42GCMController.java which basically takes care of all the GCM related tasks. Once your application gets registered with GCM, you will get regId, which you will have to register using registerWithApp42 method defined in the class as shown below

Android Manifest Settings

The next step is to include the following permissions and entries that are necessary to complete the integration process of Push Notifications in your project. Sample Android Manifest contains these entries already, however, if you are integrating in your existing project then you would have to put the following code in your Manifest too. Just replace <YOUR_APPLICATION_PACKAGE_NAME> with the value of your package name. For example, if your application package name is com.abc.myapp, use it in place of <YOUR_APPLICATION_PACKAGE_NAME> defined in the below Manifest:

You may even send push notifications to your registered app users directly through AppHQ console. Follow these simple steps to send your first push:

Click on Unified Notifications

Click on Push -> Click on Users

Select your App and users

Click on Manage from table and click on send push button as shown below:

Enter your push notification copy and click on send button as shown below. This will trigger the push notification to your app users

4. Sending Message to an iOS Device with Sound and Badge

Doesn’t matter if you have registered your application for Android Push Notifications, you may send push with sound and badges to iOS devices as well. Just pass the following JSON string in the following format:

You may also do it through AppHQ console by putting this JSON format in message text area for sending message to an iOS device with sound and badge effects

5. Sending Message to a Channel

App42 Push also supports subscription based model where users can subscribe to a channel of their interest to receive notifications related only to that channel. You can send message to a channel which will deliver your message to all the users who have subscribed to that particular channel.

App42 Push enables you to target users based on their specific profile or preference. This feature requires user preference or profile persistence in Storage Service as a prerequisite. To identify a specific user segmentation, the user profiles or preference information should be saved on App42 cloud. For example, if you are building a media app and would like to send push notifications to all the users who like sports news, you should have the preference of those users stored in App42 cloud already. This can be achieved using Storage Service as shown below:

Once your app user’s profile/preference information is saved, you can send Push Notification to the segmented user who meets specific criteria (Assuming your app user is already subscribed for push notification. For example, here you can send Push Notification to segmented users who likes Rock music as explained below.

Push notification is shot from the App42 server to GCM server and then to the devices. The delivery of the push is not guaranteed by GCM to the devices and it is stated as a best effort. Once it is delivered on the users’ devices, there are chances that a user clears it without actually reading the message

Using App42 Push Analytics, you can keep a track of how many push notifications were sent by you and out of them how many were delivered and subsequently opened by the users.
You can monitor all this from the AppHQ console which will give you a better and detailed insight of the sent push notifications.

If you would like to track how many push messages were read/opened, you would have to put the following snippet after the message is clicked and lands to your activity. This will enable the tracking of push notifications and analytics can be checked from AppHQ console.