【问题标题】:BigTextStyle notifications not expanding from FirebaseMessagingServiceBigTextStyle 通知未从 FirebaseMessagingService 扩展
【发布时间】:2016-06-15 09:02:21
【问题描述】:

我编写了以下方法来在我的 android 5.1 设备上显示 FCM 通知。当我在 FirebaseMessagingService 中运行代码时,它只是给出单行通知,如果我在我的 Activity 中运行相同的代码,它会给出可扩展的通知。

我基本上需要我的长 FCM 文本通知来扩展通知而不是显示部分通知文本。

有什么线索吗?

private void showNotif(String messageBody){

     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);

     // Constructs the Builder object.
     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
         .setSmallIcon(R.drawable.ic_launcher)
         .setContentTitle(getString(R.string.app_name))
         .setContentText(messageBody)
         .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
         .setAutoCancel(true)
         .setContentIntent(pendingIntent)
         /*
          * Sets the big view "big text" style and supplies the
          * text (the user's reminder message) that will be displayed
          * in the detail area of the expanded notification.
          * These calls are ignored by the support library for
          * pre-4.1 devices.
          */
         .setStyle(new NotificationCompat.BigTextStyle()
         .bigText(messageBody));

     // android.support.v4.app.NotificationManagerCompat mNotifManager = (NotificationManagerCompat) getSystemService(Context.NOTIFICATION_SERVICE);
     NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     // mId allows you to update the notification later on.
     mNotificationManager.notify(0, mBuilder.build());
 }

【问题讨论】:

  • 当您的应用在后台时,您是否会触发 FirebaseMessagingService?
  • 是的。我在这两种情况下都试过了。结果相同。
  • 愚蠢的问题,但在这两种情况下它都肯定在通知抽屉的顶部吗?

标签: android firebase android-notifications firebase-notifications


【解决方案1】:

这应该可以。 当顶部有其他通知时,大文本通知以正常模式显示。在测试时尝试扩展它。

【讨论】:

    【解决方案2】:

    您需要使用此方法 https://fcm.googleapis.com/fcm/send 创建通知,而不是使用 firebase 控制台,一切都会好的

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    相关资源
    最近更新 更多