FCM:我们可以发送两种类型的通知并在Android应用中打开不同的活动



我正在使用云功能实现FCM通知。在一个单个应用中,我想发送2个通知,每当收到通知时,该应用都应使用其他活动打开。

  • 假设A是将通知发送给B(B是接收器(的发件人。
    在这里,它成功发送了通知,并且每当用户单击通知时,它将发送到所需的意图
  • 现在,每当B需要将通知发送到A

*我在应用程序中收到通知,但是当我单击通知时,它将转到上面的通知意图页面。但是我需要使用数据 *

这方面的任何建议都将不胜感激。

是的,您应该使用

"android":{
   "notification"{
     "click_action":"OPEN_ACTIVITY_1"
   }
 }

然后在Android App

<intent-filter>
  <action android:name="OPEN_ACTIVITY_1" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

如果您在应用程序中接收通知有问题,则应记录每个推动输出:

public class FcmListenerService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.i(TAG, "Message received");
        // Not getting messages here? See why this may be: https://firebase.google.com/support/faq/#fcm-android-background
        Log.i(TAG, "From: " + remoteMessage.getFrom());
        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.i(TAG, "Message data payload: " + remoteMessage.getData());
        }
        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.i(TAG, "Message notification: " + remoteMessage.getNotification());
        }
    }
}

仅当应用在前景时才有效。When your app is in the background, notification messages are displayed in the system tray, and onMessageReceived is not called-https://firebase.google.com/support/faq/#fcm-android-background

最新更新