创建生成器后,Firebase FCM数据消息不会显示

时间:2019-10-02 13:13:55

标签: android push-notification firebase-cloud-messaging

我正在使用数据FCM通知,并且我在应用程序中收到的通知是一个空的通知,即使我实际上为通知填写了必要的参数,我也是如此。这是我的代码-


@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // [START_EXCLUDE]
        // There are two types of messages data messages and notification messages. Data messages are handled
        // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
        // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
        // is in the foreground. When the app is in the background an automatically generated notification is displayed
        // When the user taps on the notification they are returned to the app. Messages containing both notification
        // and data payloads are treated as notification messages. The Firebase console always sends notification
        // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
        // [END_EXCLUDE]

        Timber.d("onMessageReceived: %s", remoteMessage.getFrom());
        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            String body = remoteMessage.getNotification().getBody();


            Timber.d("Message Notification Body: %s", body);
            // broadcast
            Intent localIntent = new Intent(RECEIVED_FCM_ACTION);
            localIntent.putExtra(BD_KEY_BODY, body);
            LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
        } else {
            // At this point the notification is actually created but all information from here down is not doing anything and not actually creating the push notification. Inside the app the notification exists as an empty one. 
            Map<String, String> data = remoteMessage.getData();

            Timber.tag("remoteMessage").d(data.toString());

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify_001");
            builder.setSmallIcon(R.mipmap.ic_launcher);

            Intent intent = new Intent(this,ShareLandingActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
            builder.setContentIntent(pendingIntent);

            builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher));
            builder.setContentTitle("Notifications Title");
            builder.setContentText("notification body");
            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.notify(1, builder.build());

        }
    }

如您所见,我正在放置所有必要的信息以使通知能够通过,但该通知仍然为空,因此,我试图了解我所缺少的内容。

0 个答案:

没有答案