Skip to content

Instantly share code, notes, and snippets.

@JosephRidge
Created July 25, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosephRidge/02990afc256a8b56ea7edacbeda77703 to your computer and use it in GitHub Desktop.
Save JosephRidge/02990afc256a8b56ea7edacbeda77703 to your computer and use it in GitHub Desktop.
PushNotifications : FirebaseMessagingService
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