via Dashboard
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:
At any time, you can access the complete Android Project built with this tutorial at our Github repositories
To complete this tutorial, we need:
- An app created on Back4App.
- An android app connected to Back4App.
- Note: Follow the Install Parse SDK tutorial to create an Android Studio Project connected to Back4App.
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.
- 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.
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.
4. You will be asked to inform the package name of your Android Studio Project, as shown in the following 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.
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.
7. Now, you have to download google-services.json file and move it to your Android Studio project module root directory.
9. After that, go to the build.gradle (Module:app) file and, on the top of the file, add the code below.
10. Continue on the build.gradle (Module:app)` file and add these lines of code
Don’t forget to change these lines with the latest versions of Firebase SDKs.
To link your Firebase Project with Back4App and easily send push notification through your Dashboard, simply follow these steps:
- Find the “Android Push notification” block and click on SETTINGS > EDIT. The “Android Push notification” block looks like this:
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.
5. Click on CLOUD MESSAGING and then on Manage Service Accounts.
6. Click on Manage details (under Actions).
7. Go to Keys > ADD KEY > Create new key.
8. Choose the JSON Format and create.
9. To set up your Service Account Configuration, click on the Set Up Push Settings button
10. To finish the configuration, click on the Choose File button and select the JSON file you got from Firebase and NEXT.
- 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:
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:
Use the following permissions right after theuses-permission tags that you placed to allow your app to have access to internet.
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.
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.
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
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.
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.
- Click on > Push > Send New Push and create an audience for your push notification.
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.
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.
At this stage, you can send push notifications using the Parse Dashboard through Back4App!