Android notification icon

I have a strange problem. I have two ways to send notifications in an Android app; one from the Android service and the other through FCM.

The scripts are as follows:

  • Regardless of whether the application is running or not, the notification icon sent from the Android service is displayed correctly.
  • When the application is running, the notification icon still displays correctly if I send a notification through FCM.
  • But if the application is not running, and I send a notification through FCM, a white square is displayed instead of the notification icon.

My code in FCMService:

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Android App") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); 
+2
source share
2 answers

This is an FMC error, described in detail on the github fcm page.

https://github.com/firebase/quickstart-android/issues/4

-1
source

Most likely your problem is the difference between notification-messages 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.

The FCM Web Console is currently sending notification messages

Thus, all messages sent through the web console (or through the notification payload API) will look like this:

  • if the application is closed or in the background : FCM will display a notification. if you want to configure it, you can, but you need to provide a specific configuration (in the manifest or in the send API call), see https://firebase.google.com/docs/cloud-messaging/android/client#manifest
  • if the application is in the foreground : FCM will call onMessageReceived()

.

If you need onMessageReceived() behavior :
then you need to use data-only (no notification) message

+2
source

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


All Articles