Android Push Notification, when the application is closed, I get a different style

I use FCM to notify where everything is working fine, but while the application is open, as soon as I kill (close) the application or in the background, I get a default notification if anyone can help me configure this notification when the application is closed ( or any other suggestion). Please help me with this, Thanks in Advance

Here is my code

@Override public void onMessageReceived(RemoteMessage remoteMessage) { String title = ""; if (remoteMessage.getNotification().getTitle() != null){ title = remoteMessage.getNotification().getTitle(); } String message = ""; if (remoteMessage.getNotification().getBody() != null){ message = remoteMessage.getNotification().getBody(); } Log.e("notification","recieved"); sendNotification(title, message); } private void sendNotification(String title, String message) { Intent intent = new Intent(this, MainActivity2.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0/*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT); Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); int color=getResources().getColor(R.color.dot_dark_screen2); NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.account_outline) .setColor(color) .setDefaults(Notification.DEFAULT_SOUND) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setContentTitle(title) .setContentText(message) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setAutoCancel(true) .setSound(notificationSound) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /*ID of notification*/, notifiBuilder.build()); 

enter image description here

+5
source share
1 answer

I already posted a long explanation here: Android release notification issue

TL DR:

Most likely your problem is the difference between notifications and data messages .

Please read: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

Use notifications if you want FCM to handle the display of a notification about your customerโ€™s name. Use data messages when you want to process messages in your client application.

0
source

Source: https://habr.com/ru/post/1269250/


All Articles