我写了下面的方法来显示我的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());
}
答案 0 :(得分:0)
这应该有效。 当顶部有其他通知时,正常模式下会显示大文本通知。尝试在测试时扩展它。
答案 1 :(得分:0)
你需要使用这种方法https://fcm.googleapis.com/fcm/send来修改通知,而不是使用firebase控制台,一切都会好的