Can we show push notification payload in console.log or alert rather than the normal push notificaiton. In cordova based application?
            Asked
            
        
        
            Active
            
        
            Viewed 426 times
        
    2 Answers
2
            
            
        Yes, you can handle firebase push notification very easily, just follow the below code snippet and you can understand how to handle firebase Notification payload:
In MyFirebaseMessagingService:
 @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
            handleNotification(remoteMessage.getNotification().getBody());
        }
        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Data Payload: " + remoteMessage.getData().toString());
        }
    }
private void handleNotification(String message) {
        if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
            // app is in foreground, broadcast the push message
            Log.d(TAG, "Notification message: " + message); // It will show notification payload(message) in console log.
        }else{
            // If the app is in background, firebase itself handles the notification
        }
    }
For more information or how Firebase Notification works just follow this link
 
    
    
        Vikrant Shah
        
- 547
- 1
- 4
- 18
- 
                    if you want to show payload in alert just use alert dialog in android : https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android – Vikrant Shah Dec 04 '18 at 12:30
- 
                    // Handle incoming messages. Called when: // - a message is received while the app has focus // - the user clicks on an app notification created by a service worker // `messaging.setBackgroundMessageHandler` handler. messaging.onMessage(function(payload) { console.log('Message received. ', payload); // ... }); – Vikrant Shah Dec 06 '18 at 08:36
0
            
            
        if you are using phonegap-push-plugin then in the 'notification' event listener you can console.log() the data.
 push.on('notification', function(data) {
   console.log(data);
  });
 
    
    
        Cadis
        
- 35
- 5