Created
July 25, 2021 22:50
-
-
Save JosephRidge/02990afc256a8b56ea7edacbeda77703 to your computer and use it in GitHub Desktop.
PushNotifications : FirebaseMessagingService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jayr.pushn; | |
import android.util.Log; | |
import androidx.annotation.NonNull; | |
import com.google.firebase.messaging.FirebaseMessagingService; | |
import com.google.firebase.messaging.RemoteMessage; | |
public class MyFirebaseMessagingService extends FirebaseMessagingService { | |
String TAG = "MyFirebaseMessagingService"; | |
@Override | |
public void onNewToken(@NonNull String s) { | |
super.onNewToken(s); | |
System.out.println("Token : "+s); | |
Log.w(TAG, "Token : "+s); | |
} | |
@Override | |
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { | |
super.onMessageReceived(remoteMessage); | |
if (remoteMessage.getData().size() > 0) { | |
System.out.println("RECEIVED : = > " + remoteMessage); | |
System.out.println("From : = > " + remoteMessage.getData()); | |
} | |
if(remoteMessage.getNotification() != null){ | |
String title = remoteMessage.getNotification().getTitle(); | |
String body = remoteMessage.getNotification().getBody(); | |
System.out.println("NOTIFICATION : "+ title); | |
} | |
} | |
@Override | |
public void onDeletedMessages() { | |
super.onDeletedMessages(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment