首页 > 解决方案 > 如何根据设备分辨率在 react-native 中设置小通知图标

问题描述

我正在接收通知,现在使用默认图标。我想自定义它们,但我真的迷失了设置图标的时间。

使用react-native-firebase 通知

我已经用这个在线通知图标生成器创建了大小合适的图标。

然后我在这些地方创建了目录并使用正确的名称,如下所示(Android):

android/app/src/main/res/drawable-mdpi/ (24x24)

android/app/src/main/res/drawable-hdpi/ (36x36)

android/app/src/main/res/drawable-xhdpi/ (48x48)

android/app/src/main/res/drawable-xxhdpi/ (72x72)

android/app/src/main/res/drawable-xxxhdpi/ (96x96)

现在,我想获得正确尺寸的图像并在这里解决它。

var notification = new firebase.notifications.Notification({
                  sound: 'default',
                  show_in_foreground: true,
             })
             .android.setPriority(firebase.notifications.Android.Priority.High)
             .android.setChannelId("channel")
             .android.setSmallIcon(  <How do I put icon paths here?>  ); 

我已经阅读了一些文档和指南,但我真的不知道。引用这些路径的正确方法是什么?

标签: androidreact-native

解决方案


我们建议将以下行放入您的清单中,然后将所有不同大小的图标放入 mipmap 文件夹中,它将根据设备的分辨率调用。

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

推荐阅读