Here are quick steps/tips to integrate Firebase notifications in your client app:
- AndroidManifest :
<application>
..........<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>
- app/build.gradle:
dependencies { compile 'com.google.firebase:firebase-messaging:9.0.2'} //Make sure to apply it at the end of the file apply plugin: 'com.google.gms.google-services'
- Project level build.gradle:
dependencies { classpath 'com.google.gms:google-services:3.0.0' }
- New Classes:
- class MyFirebaseMessagingService extends FirebaseMessagingService:
- This is where notifications rendering is handled.
- Method responsible for message handling:
@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {}
- class MyFirebaseInstanceIdService extends FirebaseInstanceIdService
- This class is useful in getting the device token. This token is used if you want to send message to that particular device.
- This token can be collected: FirebaseInstanceId.getInstance().getToken() during app initialization.
- Firebase console:
- Go to Firebase Console to configure notifications: https://console.firebase.google.com/project/<projectId>/notification
- Configure and start send notifications !
- Side Notes:
- You app should be signed setup for using Firebase by generating and copying google-services.json under your app/ folder.
- You'll get opportunity to download google-services.json while configuring your Firebase Notifications via Firebase Console.
- New SHA can be added from Setting tabs under chosen project.
No comments:
Post a Comment