简体   繁体   English

如何更改本机推送通知状态栏图标?

[英]How to change react native push notifications status bar icon?

I am using firebase and react-native-push-notification to push notifications to my Android app and struggling to change the small notification icon with my own icon and none of the threads about this topic seems to help.我正在使用firebasereact-native-push-notification将通知推送到我的Android应用程序,并努力用我自己的图标更改小通知图标,并且关于此主题的任何主题似乎都没有帮助。 I have the ic_test.png located in my @mipmap folder and none of these metadata declarations in my Android manifest work:我的ic_test.png文件夹中有@mipmap并且我的 Android 清单中的这些元数据声明都不起作用:

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

2. xml <meta-data android:name="com.dieam.reactnativepushnotification.notification_icon" android:resource="@mipmap/ic_test" /> 2. xml <meta-data android:name="com.dieam.reactnativepushnotification.notification_icon" android:resource="@mipmap/ic_test" />

I am however able to change the color of the icon by adding metadata:但是,我可以通过添加元数据来更改图标的颜色:

<meta-data  
  android:name="com.dieam.reactnativepushnotification.notification_color"
  android:resource="@android:color/white"
/>

Situation:情况:

在此处输入图片说明

在此处输入图片说明

Any ideas what I might be doing wrong here?任何想法我在这里可能做错了什么?

EDIT:编辑:

Got it working for local notifications by not setting any icon metadata resource in the manifest.通过不在清单中设置任何图标元数据资源,使其适用于本地通知 I just set the following metadata resource我只是设置了以下元数据资源

<meta-data  
  android:name="com.dieam.reactnativepushnotification.notification_color"
  android:resource="@android:color/MY_COLOR"
/>

to change the background color of the icon.更改图标的背景颜色。

Also, set the following key-value pair另外,设置以下键值对

PushNotification.localNotification({...parameters, smallIcon: 'ic_test'});

When triggering a local notification.触发本地通知时。

EDIT:编辑:

I am using Firebase Cloud Messaging legacy HTTP protocol and setting the icon parameter to "ic_test" does not seem to do the trick also.我正在使用Firebase Cloud Messaging 旧版 HTTP 协议并将icon参数设置为"ic_test"似乎也不起作用。

Actually, it is showed like a white blank square because you are in the development mode, by building in production mode you can see the like exactly like your app icon.实际上,它显示为一个白色的空白方块,因为您处于开发模式,通过在生产模式下构建,您可以看到与您的应用程序图标完全相同的内容。

How ever, if you wanna make your icon you sould follow material principles .然而,如果你想制作你的偶像,你应该遵循material principles then generate all sizes by using this link and put the icon name ic_notification .然后使用此链接生成所有尺寸并放置图标名称ic_notification

Then put all sizes ic_notification in the following address:然后把所有大小的ic_notification放在如下地址:

android/app/main/res/mipmap

And add the following line to the AndroidManifest.xml file:并将以下行添加到AndroidManifest.xml文件中:

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

Clean build folder, clean caches files and use yarn start --reset-cache and then yarn android .清理构建文件夹,清理缓存文件并使用yarn start --reset-cache然后使用yarn android

Hint : if you are using emulator, aware of using Cold Boot instead of Quick Boot in your Emulator advance option.提示:如果您使用的是模拟器,请注意在模拟器高级选项中使用Cold Boot而不是Quick Boot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM