How to add Firebase Cloud Messaging into you app

Visit https://firebase.google.com/docs/cloud-messaging/android/client for more details

1) Create your app and add it as a project in firebase https://console.firebase.google.com/

CreateProject

2) Add your projects package name while creating the project

Notification

Packagename

3) Download the google-services.json (will be downloaded automatically) and save it in your app module (while opening the project in project tab)

project

4) Add the classpath dependency in project level gradle and apply plugin dependency in app level gradle

5) Add the firebase dependency for fcm to support cloud messaging

projectlevel

applevel

6) In your Manifest create two services which extend

Add these two services in your manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.sanket.pocfcm"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        ...>
        <activity ...>
        </activity>

        <service
            android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <service
            android:name=".MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
    </application>

</manifest>

7) You can test notifications from the notification console of your app https://console.firebase.google.com/project/<YOUR_PROJECT_NAME_HERE>/notification

TestNotification

Author: sanket on June 28, 2016
Category: Uncategorized