GCM 3.0 notification payload not showing android notification when app is in foreground

后端 未结 2 1524
野的像风
野的像风 2021-01-19 08:19

When i am sending a gcm message with notification(no data) payload, then the android notification is shown only if my app is in background. If the app is in foreground then

相关标签:
2条回答
  • 2021-01-19 08:30

    So it was possibility no. 3 "The behavior is like this only."

    Here is the reply from gcm-dev-support@google.com :

    This is to confirm to you that the notification payload on Android will only show on the notification tray when the app is in the background. If it is in the foreground and you would like to deploy a notification, you could consider deploying notifications similarly to this method in the sample app. It is called from onMessageReceived(). Hope this helps.

    0 讨论(0)
  • 2021-01-19 08:44

    In your Chat activity create a broadcast receiver like below and call it in the onCreate function.

    Add variable BroadcastReceiver mRegistrationBroadcastReceiver; to your class

    private void setUpBroadcastReceiver() {
    
        mRegistrationBroadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
    
                //create notification
            }
        };
    }
    
    0 讨论(0)
提交回复
热议问题