BigTextStyle通知未从FirebaseMessagingService扩展

Sya*_*m S 6 android android-notifications firebase firebase-notifications

我写了下面的方法来显示我的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());
 }
Run Code Online (Sandbox Code Playgroud)

小智 0

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