简体   繁体   English

离子2中的推送通知中不显示图标

[英]Icon is not displaying in push notifications in ionic 2

I am trying to display app icon in notification. 我正在尝试在通知中显示应用程序图标。 But it is displaying blank icon. 但它显示空白图标。

I have given pushoptions as below: 我给出了如下推送选项:

 const options: PushOptions = {
      android: {
        titleKey: 'App',
        sound: 'true',
        icon: 'res/drawable/notification_icon',
        topics: ['MyTopic']
      },
      ios: {
        alert: 'true',
        badge: false,
        sound: 'true'
      },
      windows: {}
    };

and copied the icon image as below which has resolution of 40*40px. 并复制下面的图标图像,分辨率为40 * 40px。

<resource-file src="resources/notification_icon.png" target="res/drawable/notification_icon.png" />

Is there anything that I am missing? 有什么我想念的吗? 在此输入图像描述

Update: 更新:

I followed this link : https://github.com/ionic-team/ionic-cli/issues/608 and tried it by copying all the notification icon under resources/android/notification/drawable-XYZ/ic_stat_ac_unit.png to res/drawable-XYZ/ic_stat_ac_unit.png using the following statements: 我按照以下链接: https//github.com/ionic-team/ionic-cli/issues/608并通过将resources / android / notification / drawable-XYZ / ic_stat_ac_unit.png下的所有通知图标复制到res /来尝试drawable-XYZ / ic_stat_ac_unit.png使用以下语句:

<resource-file src="resources/android/notification/drawable-hdpi/ic_stat_ac_unit.png" target="res/drawable-hdpi/ic_stat_ac_unit.png" />
        <resource-file src="resources/android/notification/drawable-mdpi/ic_stat_ac_unit.png" target="res/drawable-mdpi/ic_stat_ac_unit.png" />
        <resource-file src="resources/android/notification/drawable-xhdpi/ic_stat_ac_unit.png" target="res/drawable-xhdpi/ic_stat_ac_unit.png" />
        <resource-file src="resources/android/notification/drawable-xxhdpi/ic_stat_ac_unit.png" target="res/drawable-xxhdpi/ic_stat_ac_unit.png" />
        <resource-file src="resources/android/notification/drawable-xxxhdpi/ic_stat_ac_unit.png" target="res/drawable-xxxhdpi/ic_stat_ac_unit.png" />

and modified PushOptions in app.component.ts to : 并将app.component.ts中的PushOptions修改为:

android: {
    titleKey: 'App',
    sound: true,
    vibrate:true,
    icon: 'ic_stat_ac_unit',
    iconColor:'#343434',
    topics: ['MyTopic']
  }

Even this did not worked - Same Issue. 即使这样也行不通 - 同样的问题。

it is probably of not setting the alpha channel on the icon in the shape you want to display. 可能没有在要显示的形状的图标上设置alpha通道。 Android 5.0+ adds a white mask to all small notification icons. Android 5.0+为所有小通知图标添加了白色遮罩。 you can be using the Android Asset Studio to create the icon set as it will show you how it will look on the device to make sure you have it correct. 您可以使用Android Asset Studio创建图标集,因为它会向您显示它在设备上的外观以确保您的设置正确。

In Android 5.0+, push notification icon has to be two-color: transparent background + white foreground; 在Android 5.0+中,推送通知图标必须是双色的:透明背景+白色前景; otherwise the default app icon is taken, and anything non-transparent is displayed as white (so very likely, the user will see a white) 否则将采用默认的应用程序图标,并且任何不透明的内容都显示为白色(很可能,用户将看到白色)

I think you get your answer from below link: 我想你从以下链接得到你的答案:

https://stackoverflow.com/a/30795471/7329597 https://stackoverflow.com/a/30795471/7329597

I hope it helps you.:) 我希望它可以帮到你。:)

I used the ionic fcm plugin to fix the issue. 我使用离子fcm插件来解决问题。 I just replaced cordova push plugin with Cordova fcm plugin icon displayed. 我刚刚用Cordova fcm插件图标替换了cordova push插件。 I wasted a lot of time on push plugin.I hope this answer helps others. 我在push plugin上浪费了很多时间。我希望这个答案可以帮助别人。

Please refer to below links for more information : 有关更多信息,请参阅以下链接:

https://ionicframework.com/docs/native/fcm/ https://ionicframework.com/docs/native/fcm/

https://github.com/fechanique/cordova-plugin-fcm https://github.com/fechanique/cordova-plugin-fcm

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

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