Introduction

On the next page, click Add Firebase to your Android App.
In the Next window, you need to enter the package name for your Android application and the SHA1 finger print. Enter these values and click ADD APP. Then, one file will be downloaded i.e. google-services.json.
Add this JSON file to your App, like the below screenshot:
Now, add the following dependency in your App's build.gradle file - compile 'com.google.firebase:firebase-messaging:9.2.1'
And, you need to add one more line in the same file for Google Services.
apply plugin: 'com.google.gms.google-services'
Now, your App's Gradle file will look like the following:


- apply plugin: 'com.android.application'
- android {
- // ...
- }
- dependencies {
- // ...
- compile 'com.google.firebase:firebase-messaging:9.2.1'
- }
- // ADD THIS AT THE BOTTOM
- apply plugin: 'com.google.gms.google-services'
- <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> =
For creation, rotation, and updating of the registration token, we need another service that extends from FirebaseInstanceIdService,
On the initial start-up of the App, FCM SDK generates a registration token for the client App. This registration token is needed for sending messages to the client applications from the server. In the inTokenRefresh(), we will get the token.
- public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
- {
- @Override
- public void onTokenRefresh() {
- // Get updated InstanceID token.
- String refreshedToken = FirebaseInstanceId.getInstance().getToken();
- Log.e("Token", "Refreshed token: " + refreshedToken);
- // TODO: Implement this method to send any registration to your app's servers.
- /// sendRegistrationToServer(refreshedToken);
- }
- }
- public class MyFirebaseMessagingService extends FirebaseMessagingService
- {
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage)
- {
- // TODO(developer): Handle FCM messages here.
- // If the application is in the foreground handle both data and notification messages here.
- // Also if you intend on generating your own notifications as a result of a received FCM
- // message, here is where that should be initiated. See sendNotification method below.
- Log.e("Message", "From: " + remoteMessage.getFrom());
- Log.e("Message", "Notification Message Body: " + remoteMessage.getNotification().getBody());
- }
- }



Mayur DighePosted Jul 24, 2016, 6:13 AM
Good Work
kalu singh raoPosted Jul 23, 2016, 1:02 PM
Nice article
Vignesh ManiPosted Jul 23, 2016, 10:11 AM
Nice