A simple android firebase notification example
https://github.com/datanapps/GoogleExoPlayerSample/blob/master/screens/app-debug.apk
https://console.firebase.google.com
Project Lable :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.2'
}
}
allprojects {
repositories {
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// add firebase message
implementation 'com.google.firebase:firebase-messaging:20.0.0'
<service
android:name=".fcm.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("FCM", remoteMessage.toString());
}
}
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
// Log and toast
Log.d(TAG, token);
Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();
}
});
https://firebase.google.com/docs/cloud-messaging/android/client
https://console.firebase.google.com
Hope it will work for you. Thank you.