首页 > 解决方案 > 当应用程序被杀死或在后台时收到 fcm 通知时自动打开应用程序

问题描述

如何解决这个问题任何人给我根据这个问题的任何解决方案

收到 fcm 通知但应用未打开如何处理

public void onMessageReceived(RemoteMessage remoteMessage) {

        Intent intent = new Intent(INTENT_FILTER);
        sendBroadcast(intent);

        if (remoteMessage.getData().size() > 0) {
            utils.print(TAG, "From: " + remoteMessage.getFrom());
            utils.print(TAG, "Notification Message Body: " + remoteMessage.getData());
            //Calling method to generate notification
            if (SharedHelper.getKey(this,"loggedIn").equalsIgnoreCase(getString(R.string.True))) {

                sendNotification(remoteMessage.getData().get("message"));
            }
        }

标签: androidpush-notificationfirebase-notifications

解决方案


你应该像这样在 Manifest 中声明 firebase 服务类:

 <service android:name="your_service>
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>


推荐阅读