如何更改React Native(android)应用程序的远程推送通知图标

Anu*_*Anu 7 android push-notification react-native

我已经按照此链接在我的应用程序中执行推送通知 https://github.com/zo0r/react-native-push-notification/tree/a359e5c00954aa324136eaa9808333d6ca246171

目前显示默认的应用启动器图标.我想改变它.有没有办法做到这一点?

rah*_*rld 19

您必须遵循通知图标链接的一些规则

首先,生成各种大小的通知图标链接。并输入图标名称ic_notification

然后移动ic_notification文件夹中相应文件夹中的所有尺寸,android/app/main/res/mipmap并在AndroidManifest.xml文件中添加以下行。

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

  • 这里要添加的一件重要事情是通知图像只能是白色和灰色的。如果添加彩色图像,它们将被忽略。我在浪费了几个小时后才意识到这一点。您可以使用这个神奇的工具生成适当的通知图像 - http://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&amp;source.space.trim=1&amp;source.space.pad=0&amp;name=ic_notification (3认同)
  • 这是一个很好的答案,也可以使用此服务来创建图标:http://romannurik.github.io/AndroidAssetStudio/icons-notification.html (2认同)
  • @jamesmurphy如果是本地通知,您需要在构建本地通知对象期间传递smallIcon和largeIcon值(根据这些信息https://github.com/zo0r/react-native-push-notification#local-notifications)。 (2认同)

小智 9

在 AndroidManifest.xml 中添加以下行

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_notification" />
Run Code Online (Sandbox Code Playgroud)

创建自定义图标 ic_notification 并将它们添加到 mipmap 和 drawable 文件夹


Moh*_*lil 8

你应该先在所有android/app/src/main/res/mipmap-*中添加新图标

在所有文件夹中注意启动mipmap-*添加具有相同名称并具有适当分辨率的新图标

然后在您发送的通知对象中可以添加它的名称

{
  largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
  smallIcon: "ic_notification", // (optional) default:  "ic_notification" with fallback for "ic_launcher"
}

PushNotification.configure({
  largeIcon: "ic_launcher",
  smallIcon: "ic_notification",
}) 
Run Code Online (Sandbox Code Playgroud)

  • 我添加了像PushNotification.configure({smallIcon:"ic_notification",}) (2认同)

小智 8

我通过在应用程序关闭标记之前在 AndroidManifest.xml 中添加以下代码找到了解决方案:

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" /> 
Run Code Online (Sandbox Code Playgroud)



在通知图标生成器中生成各种尺寸的通知图标。在通知图标生成器站点上,在生成和下载文件之前设置以下选项。请注意,如果您使用自己的图像,背景必须是透明的:

  1. 文件名: notification_icon

下载文件后,将所有内容解压到 Android > src > main > res