简体   繁体   中英

How to set android push notification color and icon?

I am using react-native, amplify, and pinpoint.

I have followed several guides and stack overflow questions to set the android default color and icon for push notifications like this:

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

I have a file colors.xml inside of android/app/src/main/res/values/ with this content:

<resources>
    <color name="patch_coral">#E97A6E</color>
</resources>

And for the icon I have drawable folders inside of android/app/src/main/res/ which contain the ic_notification.png generated in android asset studio as white icons as was instructed in several places.

I have also tested with debug and release builds to see if that would change anything; however, the push notifications still do not have the default icon or color, but it does have the app icon on the right side. Here is an example:

当前的 android 推送通知示例

What needs to be changed or added to get the color and icon to replace the default android color, and square icon?

First of all create your icon: - go to photoshop or https://pixlr.com/x/ and open new image (456*456 PX) - chose a black background (you can choose any color doesn't meters, we will change it later from manifest - add the logo in the meddle

像这样

  • then cutout the logo (there is some tools with photoshop or pixlr to do this)
  • then save it as PNG)

应该看起来像这样

Then go to manifest and choose the image as default notification icon and the color in default notification color that will wrok when the app in the background or killed显现

If you want to change to work when the app in foreground u should do this in your Firebase class

Firebase 类

the results is: 结果

What you need is to send this data through your push-notification.

Then read this data from the push notification payload and apply it to the notification Builder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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