Ionic 2中推送通知中的图标未显示

4

我想在通知中显示应用程序图标,但它显示为空白图标。

我已经设置了以下推送选项:

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

并复制了下面的图标图像,分辨率为40*40像素。

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

有什么我漏掉的吗?
更新:
我按照此链接: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" />

同时修改了 app.component.ts 中的 PushOptions 为 :

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

即使这样也没有起作用 - 相同的问题。
3个回答

2
在你想要显示的图标上,可能没有设置透明通道(alpha channel)。Android 5.0+ 在所有小型推送通知图标上添加了一个白色遮罩。你可以使用Android Asset Studio来创建图标集合,并查看它在设备上的显示效果,以确保你设置正确。

在Android 5.0+中,推送通知图标必须是双色:透明背景+白色前景;否则将采用默认应用程序图标,并且任何非透明部分都将显示为白色(因此很有可能用户会看到白色)


我尝试使用 https://i.stack.imgur.com/Vr27p.png,它在 Android Asset Studio 链接上显示正常,但在设备上却无法显示。顺便提一下,我正在使用 Ionic 2。 - user1188867
@user1188867,针对Ionic,请查看此问题,它应该会指引您走向正确的路径。 - Krsna Kishore
我认为链接已经失效了,请验证并重新发布。 - user1188867
@user1188867,从评论中看来似乎无法正常工作,请尝试使用此链接 https://github.com/ionic-team/ionic-cli/issues/608。 - Krsna Kishore
我之前看过并尝试了它,但对我没有效果。我会再试一次。 - user1188867
让我们在聊天中继续这个讨论。点击此处进入聊天室 - Krsna Kishore

1

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接