【问题标题】:android - Firebase Notification Push Notification getSubTextandroid - Firebase 通知推送通知 getSubText
【发布时间】:2016-09-22 20:55:49
【问题描述】:

我使用这个类来管理我的 Android 应用程序中的通知

public class NotificationMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        String title = remoteMessage.getNotification().getTitle();
        String message = remoteMessage.getNotification().getBody();

        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
        nb.setContentTitle(title);
        nb.setContentText(message);
        nb.setSmallIcon(R.drawable.iconanotifica);
        nb.setAutoCancel(true);
        nb.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        nb.setLights(Color.BLUE, 3000, 3000);

        nb.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, nb.build());
    }
}

在 NotificationComapt.Builder 中,有一个名为 setSubText() 的方法,我想使用它。 那么,如何获取“remoteMessage.getNotification().getSubText()”呢?

【问题讨论】:

    标签: android firebase notifications firebase-cloud-messaging


    【解决方案1】:

    NotificationCompat.Builder.setSubText() 将在每个Android NotificationCompat reference documentation 的通知模板中提供一些额外的文本行。如果设备不支持大幅面通知,则无效。

    remoteMessage.getNotification() 将获得您从 Firebase 通知控制台或具有 Firebase 云消息传递实施的应用服务器发送的消息的 notification payload

    如果您想在通知消息中添加其他数据参数,可以使用以下选项进行:

    1. 在 Firebase 通知控制台的高级选项部分添加自定义数据键值对。
    2. 如果您使用 Firebase 云消息传递 (FCM),则可以发送 messages with both notification and data payload

    使用remoteMessage.getData() 在客户端应用程序中获取消息的数据负载,并使用get() 方法检索特定值,然后将其用作通知中的子文本。

    希望这会有所帮助!

    【讨论】:

    • 是的,它有效。但我使用 android 应用程序发送通知,这是由 php 文件管理的。只有当我从数据库发送通知时,我才会看到 subText,但如果我从应用程序发送,则不会。你能帮忙吗?
    • 嘿@Simone,你能把这个问题展开更多吗?如果它与原始问题不同,请更新您的问题或接受我的回答并创建一个新线程。
    • 不,这不是我想要遵循的解决方案。我需要从 android 应用发送此通知并设置潜文本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 2018-09-19
    • 1970-01-01
    相关资源
    最近更新 更多