我无法从FCM通知中获取String Extra数据

时间:2019-05-31 14:44:47

标签: android string firebase firebase-cloud-messaging firebase-notifications

当我尝试从FCM发送的通知中获取String Extra时,我得到的是空数据。

这是我发送额外字符串值的代码:

    Intent mOpenNotification = new Intent(CLICK_ACTION);
    mOpenNotification.putExtra("USER_UID", remoteMessage.getData().get("from_user"));
    PendingIntent mResultPendingIntent = PendingIntent.getActivity(this, 0, mOpenNotification, PendingIntent.FLAG_UPDATE_CURRENT);

这是我的Firebase FCM代码,用于显示通知:

            mBuilder = new Builder(getApplicationContext(), CHANNEL_ID);
            mBuilder.setSmallIcon(R.mipmap.ic_launcher);
            mBuilder.setPriority(PRIORITY_HIGH);
            mBuilder.setContentTitle(NOTIFICATION_TITLE);
            mBuilder.setContentText(NOTIFICATION_BODY);
            mBuilder.setContentIntent(mResultPendingIntent);
            mBuilder.setSound(DEFAULT_NOTIFICATION);
            mBuilder.setAutoCancel(true);
            mBuilder.setGroup("SYSTEM");
            mBuilder.build();

这是他尝试获取我的活动中Extra String的值的方法:

String USER_UID = getIntent().getStringExtra("USER_UID");

这是打开的活动的Android清单的XML代码。

<activity
    android:name=".network.home.social.MessagesPrivate"
    android:label="@string/title_activity_messages_private"
    android:theme="@style/AppTheme.NoActionBar"
    android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
    <intent-filter>
        <action android:name="com.raven.okami.notifications.TARGET_NOTIFICATION_MESSAGE"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

0 个答案:

没有答案