Почему значок push-уведомления становится белым вместо значка приложения Android с помощью FCM? - PullRequest
1 голос
/ 24 июня 2019

В зефире = Показывается белый значок.в Марсмелло.В Kitkat = отображается значок приложения.В Oreo = отображение уведомления со значком приложения, когда фоновое изображение, но когда на переднем плане уведомление приходит, но не отображается.

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(TAG, "From: " + remoteMessage.getFrom());

    if (remoteMessage == null)
        return;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
        handleNotification(remoteMessage.getNotification().getBody());
    }

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        //Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

        String title = remoteMessage.getData().get("title");
        String message = remoteMessage.getData().get("body");
        String click_action = remoteMessage.getData().get("click_action");
        System.out.println("clickAction==@@@" + click_action);

        handleDataMessage(title, message, click_action);
    }
}

private void handleNotification(String message) {

    Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION);
    pushNotification.putExtra("message", message);
    LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
    // play notification sound
    NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
    notificationUtils.playNotificationSound();

}



@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void handleDataMessage(String noti_title,String noti_message,String noti_click_action) {

    try {

        System.out.println("noti_title="+ noti_title);
        System.out.println("noti_message="+ noti_message);
        System.out.println("noti_click_action="+ noti_click_action);

        Intent intent=new Intent(noti_click_action);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBuilder=new NotificationCompat.Builder(this);
        notificationBuilder.setContentTitle(noti_title);
        notificationBuilder.setContentText(noti_message);
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0,notificationBuilder.build());


    } catch (Exception e) {
        Log.e(TAG, "Exception: " + e.getMessage());
    }
}


/**
 * Showing notification with text only
 */
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void showNotificationMessage(Context context, String title, String message, String timeStamp, Intent intent) {
    notificationUtils = new NotificationUtils(context);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notificationUtils.showNotificationMessage(title, message, timeStamp, intent);
}

/**
 * Showing notification with text and image
 */
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void showNotificationMessageWithBigImage(Context context, String title, String message, String timeStamp, Intent intent, String imageUrl) {
    notificationUtils = new NotificationUtils(context);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notificationUtils.showNotificationMessage(title, message, timeStamp, intent, imageUrl);
}

Используя приведенный выше код, я получаю другой значок в другой версии. Есть ли ошибка?

Ответы [ 3 ]

0 голосов
/ 25 июня 2019

Насколько я помню, у вас должен быть белый прозрачный значок. Так что если у вас есть цветной значок, он будет отображаться по-другому.

notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);

Это обычная ошибка. Вы должны создать свой собственный PNG и положить его в @drawable. Нарисуйте силуэт, содержащий только белый цвет (и прозрачный фон).

0 голосов
/ 25 июня 2019

Вам необходимо добавить это в AndroidManifest.xml

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

Кроме того, для вашего построителя уведомлений установите тот же значок с помощью

notificationBuilder.setSmallIcon(R.drawable.statusbar_not_icon)

Как создать значок в строке состояния?

0 голосов
/ 24 июня 2019

похоже, что сервер отправляет данные в ключ уведомления, а затем управление значками происходит с сервера, и вы не можете с этим справиться, попросите сервер отправить вам уведомление с нулем и отправить все данные в ключ данных

...