gpt4 book ai didi

android - 无法更改从 Firebase 控制台发送的 Firebase 云消息传递通知的默认图标

转载 作者:行者123 更新时间:2023-11-29 23:33:07 27 4
gpt4 key购买 nike

所以我在我的 Qt 应用程序中集成了 Firebase 云消息传递,并且我正在尝试为通知设置一个自定义图标(默认情况下显示一个灰色的圆圈)。我知道这个问题之前在这里被问过Notification Icon with the new Firebase Cloud Messaging system .现在我已经按照帖子(和其他类似帖子)中的建议进行操作。在我的 list 文件中,我添加了:

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

然后我根据 Google 提供的自定义状态栏图标规范创建了不同的图标(透明背景上的白色)。我的目标 SDK 设置为 26。尽管如此,通知始终显示默认图标而不是我的自定义图标。我从 Firebase 控制台网站发送通知。我知道一些用户建议使用 API 发送通知,因为它似乎可以解决这个问题,但是否有可能避免这种情况并成功使用 Firebase 控制台?

最佳答案

好的,所以我找到了解决问题的方法。问题是我在 Android 8.0 Oreo 上测试应用程序。从此版本的 Android 开始,Google 要求应用程序使用 Notification Channels和应用程序需要创建一个默认的通知 channel 。因此,我在 onCreate 方法中将以下代码添加到应用程序的主要 Activity 中:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create channel to show notifications.
String channelId = getString(R.string.default_notification_channel_id);
String channelName = getString(R.string.default_notification_channel_name);
NotificationManager notificationManager =
getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(new NotificationChannel(channelId,
channelName, NotificationManager.IMPORTANCE_LOW));
}

然后在 list 文件中添加默认的通知id:

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>

关于android - 无法更改从 Firebase 控制台发送的 Firebase 云消息传递通知的默认图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52484893/

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