Облачные сообщения Firebase (fcm-node и android), пользовательский макет уведомлений - PullRequest
0 голосов
/ 30 ноября 2018

Мне нужно создать собственный макет для моего push-уведомления.Я пишу код прихода, но он не работает для меня:

  @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        String date="", time="", title="", body="";
        String click_action = "";
        RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.custom_notification);
             date = remoteMessage.getData().get("date");
             time = remoteMessage.getData().get("time");
             title = remoteMessage.getNotification().getTitle();
             body = remoteMessage.getNotification().getBody();
            click_action = remoteMessage.getNotification().getClickAction();
        Intent resultIntent = new Intent(click_action);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(ResultActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        1,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(title)
                .setContentText(body + "\n" + date + "\n" + time )
                .setCustomContentView(notificationLayout)
                .setAutoCancel(true)
                .setContentIntent(resultPendingIntent);


        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification.build());


    }

И это мой код сервера (node.js / fcm-node):

var message = {
            to: token,
            notification: {
                title: title, //title of notification
                body: body, //content of the notification
                sound: "default",
                icon: "ic_notification" //default notification icon
              },
            data: {
              date: date,
              time: time
         }

  };
  fcm.send(message, function(err, response){
       if (err) {
           console.log("Notification not sent");
           res.status(200).json({success:false})
       } else {
           console.log("Successfully sent with response: ", response);
           res.status(200).json({success:true})
       }
   });

И данные полезной нагрузкипусто, когда я пытаюсь отправить его в Activity.Пожалуйста, помогите мне

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...