gpt4 book ai didi

Android通知图标颜色有时是白色的,有时是彩色的

转载 作者:行者123 更新时间:2023-11-30 01:16:31 29 4
gpt4 key购买 nike

我的 Android 应用程序有一个小问题。它通过 FCM 接收通知并将它们显示为推送通知。到目前为止一切正常,但奇怪的问题是,有时图标是白色的,有时是彩色的。

当应用程序在屏幕上打开并且此时我收到推送通知时,彩色推送通知显示在屏幕顶部。

当应用程序关闭时,我会收到带有白色图标的推送通知。

附上截图: Screenshot

这是创建推送通知的代码 fragment :

        Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setAutoCancel(true)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setPriority(Notification.PRIORITY_HIGH)
.setColor(Color.parseColor("#83c3ed"))
.setLights(Color.RED, 1000, 500)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
inboxStyle.setBigContentTitle("WetterApp");
inboxStyle.addLine(notification.getTitle());
inboxStyle.addLine(notification.getBody());
notificationBuilder.setStyle(inboxStyle);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notificationBuilder.build());

我的移动设备是 Android 6.0.1,我的 SDK 版本是 23。

感谢您的帮助。

最佳答案

嗯,我认为问题有所不同。当应用程序在屏幕上打开时,我用于创建通知的代码只会被调用。当我收到通知并关闭应用程序时,Android 系统会自动处理该通知。

我必须在发送到 FCM 服务器的通知中设置颜色:

 $data = [
'notification' => [
'title' => 'Warnung: Wohnzimmer',
'text' => 'Innen: 20,3°C Außen: 24,5°C, Tendenz: -0,2°C',
'color' => '#83c3ed',
'sound' => 'default'
],
'to' => '/topics/testNotification'
];

现在我在应用程序中以及关闭应用程序时都会看到一个浅蓝色背景图标。

关于Android通知图标颜色有时是白色的,有时是彩色的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37796695/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com