Ho scritto il metodo seguente per mostrare la notifica FCM sul mio dispositivo Android 5.1. Quando eseguo il codice all'interno di un FirebaseMessagingService, è sufficiente dare una notifica a linea singola, dove se eseguo lo stesso codice all'interno della mia attività, fornisce notifiche espandibili.Notifiche BigTextStyle non espandibili da FirebaseMessagingService
Fondamentalmente ho bisogno delle mie lunghe notifiche di testo FCM per essere espansa sulle notifiche piuttosto che per mostrare il testo di notifica parziale.
Eventuali cavi?
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());
}
stai innescando il tuo FirebaseMessagingService quando la vostra applicazione è sullo sfondo? – mgcaguioa
sì. L'ho provato in entrambi i casi. Stesso risultato –
Domanda sciocca, ma in entrambi i casi è sicuramente nella parte superiore del pannello delle notifiche? – IanS