简体   繁体   中英

Android Push notification Status Icon issue

I am facing issue while using push notification Firebase, Issue : App Icon appears white on a marshmallow and above, so I created the white and transparent set of icons, now push notification icons to appear as I needed but only when the app is on the foreground when a user gets a notification and app is closed the icon appears white itself.

My Manifest

<application
        android:name="com.xxxx"
        android:allowTaskReparenting="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_xxxx"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme">

Notification Code : when I get push notification

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder notificationBuilder;
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                notificationBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.xxxxxx)
                        .setColor(getResources().getColor(R.color.accent))
                        .setContentTitle(messageTitle)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(contentIntent);
            } else {
                notificationBuilder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(messageTitle)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(contentIntent);
            }



            NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(count, notificationBuilder.build());

on Message Recieve Code

 @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //Displaying data in log
        //It is optional
        Log.d(TAG, "Notification Message TITLE: " + remoteMessage.getNotification().getTitle());
        Log.d(TAG, "Notification Message BODY: " + remoteMessage.getNotification().getBody());
        Log.d(TAG, "Notification Message DATA: " + remoteMessage.getData().toString());

        //Calling method to generate notification
        //remoteMessage.getNotification().getBody()
        sendNotification(remoteMessage.getNotification().getTitle(),
                remoteMessage.getNotification().getBody(), remoteMessage.getData());
    }

There are two types of notification there.

1.) using default params

    String title = remoteMessage.getNotification().getTitle();
    String body = remoteMessage.getNotification().getBody();

Server Side Code:

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

This type of implementation only works when the app is open or in background. You will notified message received ( blank notification will appear as you said) but you won't get any data from it.

2.) using map

   Map data =  remoteMessage.getData();

Server Side Code:

{
  "message":{
    "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "This is an FCM notification message!",
      "title" : "FCM Message",
      }
   }
}

This will receive even after the app closed. It won't produce the blank white notification.

IF its issue with notification icon as white. Try adding this code in manifest

<meta-data 
android:name="com.google.firebase.messaging.default_notification_icon" 
android:resource="@drawable/app_icon" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM