gpt4 book ai didi

android - BigTextStyle 通知未从 FirebaseMessagingService 扩展

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:32 25 4
gpt4 key购买 nike

我编写了以下方法在我的 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());
}

最佳答案

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

关于android - BigTextStyle 通知未从 FirebaseMessagingService 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37830790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com