Android
Push Notifications

via Dashboard

23min

Parse Server push notifications setup

Introduction

This section explains how you can send push notifications using Firebase Cloud Messaging and Parse Dashboard through Back4App.

This is how it will look like:

Document image


At any time, you can access the complete Android Project built with this tutorial at our Github repositories

Prerequisites

To complete this tutorial, we need:

1 - Link your Firebase Project with your Android Studio Project

To send push notifications through your Dashboard, you will have to create a Project at Firebase Website and link it to your Android Studio Project. To do so, follow the steps described below:

Pay attention to the steps below because you are not going to follow exactly the same steps that Firebase suggests.

  1. Go to Firebase Website and log in with a Google Account.
  2. At Firebase Website, in the right corner click on GO TO CONSOLE and click on Add Project, then give your Project a name follow the steps to create a new project.
Document image




3. Then, connect your Android Studio Project to the Firebase Project you created. To do so, click on the Android icon, as shown in the following image.

Document image


4. You will be asked to inform the package name of your Android Studio Project, as shown in the following image.

Document image


5. To discover the package name of your Android Studio Project, leave the Firebase page opened and go to your Project in Android Studio and go to app > manifest > AndroidManifest.xml. In your manifest file you will be able to find the package name of your project, as you can see in the image below.

Document image


6. Copy the package name in the required box at the Firebase page. You can also fill the other fields, but they are optional. After that, click on the Register app button.

Document image


7. Now, you have to download google-services.json file and move it to your Android Studio project module root directory.

Document image

1 classpath 'com.google.gms:google-services:latest.version.here'

9. After that, go to the build.gradle (Module:app) file and, on the top of the file, add the code below.

1 apply plugin: 'com.google.gms.google-services'

10. Continue on the build.gradle (Module:app)` file and add these lines of code

1 // Don't forget to change the line below with the latest versions of Firebase SDKs 2 implementation 'com.google.firebase:firebase-core:latest.version.here' 3 implementation 'com.google.firebase:firebase-messaging:latest.version.here'

Don’t forget to change these lines with the latest versions of Firebase SDKs.

2 - Link your Firebase Project with Back4App

To link your Firebase Project with Back4App and easily send push notification through your Dashboard, simply follow these steps:

  1. Go to Back4App Website, log in, find your app and click on Server Settings.
  2. Find the “Android Push notification” block and click on SETTINGS > EDIT. The “Android Push notification” block looks like this:
Document image


3. Leave the Back4App Android Push Notification page you visited opened and go to your project on the Firebase Website.

4. Click on the settings icon and then the Project Settings button, as shown below.

Document image


5. Click on CLOUD MESSAGING and then on Manage Service Accounts.

Document image


6. Click on Manage details (under Actions).

Document image


7. Go to Keys > ADD KEY > Create new key.

Document image


8. Choose the JSON Format and create.

Document image


9. To set up your Service Account Configuration, click on the Set Up Push Settings button

Document image


10. To finish the configuration, click on the Choose File button and select the JSON file you got from Firebase and NEXT.

Document image




3 - Set up the Manifest File

  1. Open your Project at Android Studio and go to app > manifest > AndroidManifest.xml. In this file, use the code below right after the meta-data tags that are inside the application tag:
XML


Don’t forget to insert theGCM Sender IDyou obtained at Firebase in this line of code.

2. Use the following code right before the application tag ends:

AndroidX
Android


Use the following permissions right after theuses-permission tags that you placed to allow your app to have access to internet.

XML


You added permissions to allow internet access in the Install Parse SDK Tutorial instructions. If you didn’t, access Install Parse SDK Tutorial and follow its steps.

4 - Set up build.gradle (Module: app)

Install the Parse FCM SDK and the Parse Bolts SDK for Android. To do so, open build.gradle (Module: app) and add the code below in the dependecies{} tag.

1 // Don't forget to change the lines belows with the latest versions these SDKs 2 implementation "com.github.parse-community.Parse-SDK-Android:fcm:latest.version.here" 3 implementation 'com.parse.bolts:bolts-android:latest.version.here'

Don’t forget to change these lines with the latest versions of these SDKs.

If you are not using AndroidX, you cannot use the latest version. Check the changelog

5 - Create an installation

Every Parse application installed on a device registered for push notifications has an associated Installation object that stores all the data needed to target push notifications.

In Android, Installation objects are available through the ParseInstallation class. This class uses the same API for storing and retrieving data. To access the current Installation object from your Android app, use the ParseInstallation.getCurrentInstallation() method.

In the first time you save a ParseInstallation, Parse will add it to your Installation class and it will be available for targeting push notifications.

To create a ParseInstallation in your app, go to your Android Studio Project and in the Java file called App that extends Application that you created to initialize the Parse SDK, on its onCreate method, right after Parse.initialize() call, use the following code to create a ParseInstallation.

1 ParseInstallation installation = ParseInstallation.getCurrentInstallation(); 2 installation.put("GCMSenderId", INSERT_YOUR_SENDER_ID); 3 installation.saveInBackground();

Don’t forget to insert theGCM Sender IDyou obtained at Firebase in the code above.

If you don’t have an App.java file as described in this step, access the Install Parse SDK for Android documentation and make sure that you have followed all the steps required to install Parse SDK correctly. If you do not install Parse SDK properly your facebook login with Parse will not work.

6 - Test your app

  1. Go to Back4App Website, log in, find your app and click on Dashboard.
  2. Click on > Push > Send New Push and create an audience for your push notification.
Document image


3. Write your message and look at the preview by clicking at the Android option.

4. If you already reviewed the push notification and you want to send it, click onSend push.

Document image


You may explore the other options for Push Notification at Parse Dashboard. There, it’s also possible to look at Past Pushes you sent and the Audiences you created for them.

It’s done!

At this stage, you can send push notifications using the Parse Dashboard through Back4App!