简体   繁体   English

IONIC 2:推送通知图标白色正方形

[英]IONIC 2 : Push notifications icon white square

When my Android phone (Andoid 8.0) receives a push notification from my app, the icon is blank/white. 当我的Android手机(Andoid 8.0)从我的应用收到推送通知时,该图标为空白/白色。 It works when I use $ ionic cordova resources --icon with an icon with transparent background, but when I do that my app icon has no background, and I don't want that. 当我使用$ ionic cordova resources --icon带有透明背景的图标时,它可以工作,但是当我这样做时,我的应用程序图标没有背景,并且我不想要那样。

It's possible to use differents icons for app and for notification ? 可以在应用和通知中使用不同的图标吗? I tried a lot of things but nothing works. 我尝试了很多事情,但没有任何效果。

I'm using Ionic 2 push plugin to show push notification, I used this post to do my code : https://ampersandacademy.com/tutorials/ionic-framework-version-2/push-notification-in-ionic-2-native-plugin-version-2-3-with-firebase-hosting-service-provider 我正在使用Ionic 2推送插件来显示推送通知,我使用了这篇文章来编写我的代码: https : //ampersandacademy.com/tutorials/ionic-framework-version-2/push-notification-in-ionic-2-带有Firebase托管服务提供商的native-plugin-version-2-3-

Any help would be greatly appreciated ! 任何帮助将不胜感激 !

Yes you can use a different icon for your notifications. 是的,您可以为通知使用其他图标。 Just specify an icon in your PushOptions when you initialize the push plugin. 初始化Push插件时,只需在PushOptions中指定一个图标即可。 If you dont specify an icon it uses the app icon by default. 如果您未指定图标,则默认情况下会使用应用程序图标。

const options: PushOptions = {
   android: {
       icon: your_drawable_icon
   }
};

const pushObject: PushObject = this.push.init(options);

Read more about available (android) options in the Ionic Doc and for more details directly in the phonegap-push-plugin repo Ionic Doc中阅读有关可用(android)选项的更多信息,并在phonegap-push-plugin存储库中直接了解更多详细信息

You have to add icon manually in your platform project (Android Native method) 您必须在平台项目中手动添加图标(Android本机方法)

  1. create ic_notification.png 创建ic_notification.png
  2. find directory \\platforms\\android\\res\\ 查找目录\\platforms\\android\\res\\
  3. In res directory you can see many drawable or mipmap directory, Copy ic_notification in all these directories. 在res目录中,您可以看到许多drawablemipmap目录,在所有这些目录中复制ic_notification。
  4. Open AndroidManifest.xml located in \\platforms\\android\\ 打开\\platforms\\android\\ AndroidManifest.xml
  5. Inside <application > ... </application > tag add following config <application > ... </application >标记内,添加以下配置

    if drawable 如果可绘制

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

    if mipmap 如果mipmap

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

***Note this setting may overwritten if you clean and rebuild your project. ***请注意,如果您清理并重建项目,此设置可能会被覆盖。 or if you run platform remove/update/add command 或者如果您运行平台删除/更新/添加命令

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

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