tuo JSON notifica dovrebbe includere
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
per mostrare un messaggio nella barra delle notifiche utilizzando la funzionalità di default di Firebase quando l'applicazione è chiusa. Scopri this per ulteriori informazioni
alternativa
onMessageReceived
dovrebbe far scattare in tutti i casi, in modo da poter generare la notifica utilizzando
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
Puoi pubblicare il tuo carico? –
Cosa intendi con il nuovo FCM? Stai inviando i messaggi dal tuo server delle app o stai utilizzando il compositore Firebase per inviare i messaggi? –
sì sto inviando dal mio server – redochka