Push Notification helps you in sending event or alert to your app users even when they are not logged into app. App42 uses GCM (Google Cloud Messaging) to send Push Notification on android devices. Here are the few easy steps to get stated with App42 Android Push Notification.
Create a project and get your Project Id from google developer console.
Click on services option in Google developer console and enable Google Cloud Messaging for Android service.
Click on API Access tab and create a new server key for your application with blank server information.
Go to AppHQ console and click on Push Notification and select Android Settings in Settings option.
Select your app and copy server key that is generated in Google developer console in above step and submit it.
Download sample project from our GitHub Repo
Unzip the downloaded file and import it in eclipse.
Open MainActivty.java file in and pass required information in onCreate method as shown below
The Above snippet will do all the stuff for you seamlessly. Once app will get started it will register your app with GCM as well as with App42 platform for push notification usage. It uses storeDeviceToken method to register app with App42 server. This is only one time activity and will be done when app will be opened.
If you want to go in detail about the sample code, please see GCMIntentService.java which does all GCM related work like registering with GCM and App42 server and generating notification. This class overrides GCMBaseIntentService class and overrides onMessage and onRegister method. Once your app gets registered with GCM, its onRegister method gets invoked, which further calls registerWithApp42 method defined in the class as shown below
Following Permissions and entries are required to integrate Push Notification in your project. Sample Android Manifest contains these entries already however if you are integrating in your existing project put these lines in your Manifest too. You have to replace <YOUR_APPLICATION_PACKAGE_NAME> with the value of your package name. Also, if you are integrating in your project, GCMIntentService must be placed inside application package. For example if your application package name is com.abc.myapp, you have to use it in place of <YOUR_APPLICATION_PACKAGE_NAME> defined in below Manifest and also put GCMIntentService under com.abc.myapp package in your source.
Once your app is registered you are ready to send message to your app user using following code snippet from any App42 SDK (Android/Java/WP etc)
you can also send push messages to your registered app user directly from AppHQ console. To do this, go to AppHQ console and click on Push NotificationClick on User Link Select your Appselect your user from table and click on send message button. This will open a pop up to type your message, once you are done click on send button. This will trigger a push notification message to your app user.
If you want to send push message with sound and badge effect on iOS device, you have to pass JSON string in below format
You can also do it from AppHQ by putting this JSON format in message text area for sending message to iOS device with sound and badge effect.
App42 Push notification also supports channel subscription model where user can subscribe on channel of his interest to receive the notification. You can send message to channel which will deliver message to all users who are subscribed to that channel. A channel can be created from AppHQ console. Go to Push NotificationChannel Select your AppClick on Create Channel button
Once channel is created you can ask user for subscription on the channel. Below is the code snippet for the same
You can also schedule message to your app user on specified time from AppHQ console. To do this, got to Push NotificationClick on User linkSelect your appselect target users/device and click on schedule message button. Now type your message in pop up and pass your time to schedule the message.
Message scheduling on channel can be done in similar way. Go to Push NotificationClick on Channel linkSelect your appselect target channel and click on schedule message button. Now type your message in pop up and pass your time to schedule the message.
Push notification received on user device can be configured and can be controlled from the code written in generateNotification method as shown below
You can specify which Activity should be opened once user clicks on message. Its configured inside AndroidManifest.xml as shown below
Push notification goes from App42 server to GCM server and then device. Delivery of Push notification is not guaranteed from GCM to device and it is stated as best effort. Once it is delivered on user device, there might be a chance that user clears it without actually Opening the message.
Using App42 Push Analytics, you can track how many push notification was sent from your side, how many were delivered and how many were opened by the user. You can see these analytics from AppHQ console which will give a better insight of push notification campaign.