via Dashboard
23 min
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 at any time, you can access the complete android project built with this tutorial at our github repositories kotlin example repository https //github com/templates back4app/android parse sdk kotlin java example repository https //github com/templates back4app/android parse sdk java prerequisites to complete this tutorial, we need android studio https //developer android com/studio/index html an app created on back4app note follow the new parse app tutorial https //www back4app com/docs/get started/new parse app to learn how to create a parse app on back4app an android app connected to back4app note follow the install parse sdk tutoria https //www back4app com/docs/android/parse android sdk l to create an android studio project connected to back4app a device (or virtual device https //developer android com/studio/run/managing avds html ) running android 4 0 (ice cream sandwich) or newer 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 https //firebase google com/ 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 go to firebase website https //firebase google com/ and log in with a google account at firebase website, in the right corner click on \<font color="#2166ae">go to console\</font> and click on \<font color="#2166ae">add project\</font> , 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 \<font color="#2166ae">app\</font> > \<font color="#2166ae">manifest\</font> > \<font color="#2166ae">androidmanifest xml\</font> 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 \<font color="#2166ae">register app\</font> button 7\ now, you have to download \<font color="#2166ae">google services json\</font> file and move it to your android studio project module root directory 1 classpath 'com google gms\ google services\ latest version here' 9\ after that, go to the \<font color="#2166ae">build gradle (module\ app)\</font> 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 go to back4app website https //www back4app com/ , log in, find your app and click on \<font color="#2166ae">server settings\</font> find the “android push notification” block and click on \<font color="#2166ae">settings\</font> > \<font color="#2166ae">edit\</font> 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 https //firebase google com/ 4\ click on the settings icon and then the \<font color="#2166ae">project settings\</font> button, as shown below 5\ click on \<font color="#2166ae">cloud messaging\</font> 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 3 set up the manifest file open your project at android studio and go to \<font color="#2166ae">app\</font> > \<font color="#2166ae">manifest\</font> > \<font color="#2166ae">androidmanifest xml\</font> in this file, use the code below right after the \<font color="#2166ae">meta data\</font> tags that are inside the \<font color="#2166ae">application\</font> tag 1 \<meta data android\ name="com parse push gcm sender id" 2 android\ value="insert your sender id" /> don’t forget to insert the \<font color="#2166ae">gcm sender id\</font> you obtained at firebase in this line of code 2\ use the following code right before the \<font color="#2166ae">application\</font> tag ends androidx 1 \<service android\ name="com parse fcm parsefirebasemessagingservice" android\ exported="false"> 2 \<intent filter> 3 \<action android\ name="com google firebase messaging event"/> 4 \</intent filter> 5 \</service> 6 7 \<receiver android\ name="com parse parsepushbroadcastreceiver" android\ exported="false"> 8 \<intent filter> 9 \<action android\ name="com parse push intent receive" /> 10 \<action android\ name="com parse push intent open" /> 11 \<action android\ name="com parse push intent delete" /> 12 \</intent filter> 13 \</receiver> android 1 \<service android\ name="com parse fcm parsefirebaseinstanceidservice" android\ exported="false"> 2 \<intent filter> 3 \<action android\ name="com google firebase instance id event" /> 4 \</intent filter> 5 \</service> 6 7 \<service 8 android\ name="com parse fcm parsefirebasemessagingservice" android\ exported="false"> 9 \<intent filter> 10 \<action android\ name="com google firebase messaging event"/> 11 \</intent filter> 12 \</service> 13 14 \<receiver android\ name="com parse parsepushbroadcastreceiver" android\ exported="false"> 15 \<intent filter> 16 \<action android\ name="com parse push intent receive" /> 17 \<action android\ name="com parse push intent open" /> 18 \<action android\ name="com parse push intent delete" /> 19 \</intent filter> 20 \</receiver> use the following permissions right after the \<font color="#2166ae">uses permission\</font> tags that you placed to allow your app to have access to internet 1 \<uses permission android\ name="android permission wake lock" /> 2 \<uses permission android\ name="android permission vibrate" /> 3 \<uses permission android\ name="android permission receive boot completed" /> 4 \<uses permission android\ name="android permission get accounts" /> 5 \<uses permission android\ name="com google android c2dm permission receive" /> you added permissions to allow internet access in the install parse sdk tutorial https //www back4app com/docs/android/parse android sdk 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 \<font color="#2166ae">build gradle (module app)\</font> and add the code below in the \<font color="#2166ae">dependecies{}\</font> 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 https //github com/parse community/parse sdk android/blob/master/changelog md 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 \<font color="#2166ae">parseinstallation\</font> class this class uses the same api for storing and retrieving data to access the current installation object from your android app, use the \<font color="#2166ae">parseinstallation getcurrentinstallation()\</font> 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 \<font color="#2166ae">parseinstallation\</font> in your app, go to your android studio project and in the java file called \<font color="#2166ae">app\</font> that extends application that you created to initialize the parse sdk, on its \<font color="#2166ae">oncreate\</font> method, right after \<font color="#2166ae">parse initialize()\</font> call, use the following code to create a \<font color="#2166ae">parseinstallation\</font> 1 parseinstallation installation = parseinstallation getcurrentinstallation (); 2 installation put ( "gcmsenderid" , insert your sender id ); 3 installation saveinbackground (); don’t forget to insert the \<font color="#2166ae">gcm sender id\</font> you obtained at firebase in the code above if you don’t have an \<font color="#2166ae">app java\</font> file as described in this step, access the install parse sdk for android https //www back4app com/docs/android/parse android sdk 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 go to back4app website https //www back4app com/ , log in, find your app and click on \<font color="#2166ae">dashboard\</font> click on > \<font color="#2166ae">push\</font> > \<font color="#2166ae">send new push\</font> 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 on \<font color="#2166ae">send push\</font> you may explore the other options for push notification at \<font color="#2166ae">parse dashboard\</font> there, it’s also possible to look at \<font color="#2166ae">past pushes\</font> you sent and the \<font color="#2166ae">audiences\</font> you created for them it’s done! at this stage, you can send push notifications using the parse dashboard through back4app!