如何显示来自其他用户的通知?

How to show notification from other user ?

我在使用 android qiscus sdk 实现通知时遇到了一些问题。

我创建 class FirebaseService 扩展 FirebaseMessagingService。

但是,当有人与我聊天时,我无法在 onMessageReceived 中收到消息。任何人都可以帮助我吗?谢谢。

try {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            String title = "" + "";

            PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            if (defaultSound == null) {
                defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
                if (defaultSound == null) {
                    defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
                }
            }

            Notification.Builder builder = new Notification.Builder(context)
                    .setContentTitle(title)
                    .setContentText(message)
                    .setContentIntent(intent)
                    .setSmallIcon(icon)
                    .setLights(Color.BLUE, 20, 80)
                    .setAutoCancel(true)
                    .setSound(defaultSound);

            if (bitmap != null) {
                builder.setLargeIcon(bitmap);
            }

            Notification not = new Notification.BigTextStyle(builder).bigText(message).build();

            if (defaultSound == null) {
                not.defaults |= Notification.DEFAULT_VIBRATE;
                not.defaults |= Notification.DEFAULT_SOUND;
            }

            notificationManager.notify(0, not);
        }
        catch (Exception e) {
            e.printStackTrace();
        }`

您必须使用 QiscusFirebaseService 进行扩展并将 remoteMessege 设置为 handleMessageReceived。

QiscusFirebaseService.handleMessageReceived(远程消息)

查看详细示例 https://gist.github.com/fauzisho/64b89df651c91b1dd6d4d096c8d826ca

希望能帮到您解决问题