简体   繁体   English

如何在 Cordova Android 应用程序中更改 OneSignal 通知的小图标?

[英]How to Change Small Icon of OneSignal Notifications in a Cordova Android App?

I created an app using Cordova and Phonegap I use OneSignal for sending Push Notification but when I send the Notification to the user it shows a small bell icon and a Large Bell icon .我使用 Cordova 和 Phonegap 创建了一个应用程序,我使用 OneSignal 发送推送通知,但是当我向用户发送通知时,它会显示一个小铃铛图标和一个大铃铛图标。 I already change the large one because it uses link and small one use resource so I am not able so please help me.我已经更改了大的,因为它使用链接,而小的使用资源,所以我不能,所以请帮助我。

Create a transparent image and name it as ic_stat_onesignal_default, and call it where it requires.创建一个透明图像并将其命名为 ic_stat_onesignal_default,并在需要的地方调用它。 It will work.它会起作用。

@Yokesh Is correct that the icon must be named ic_stat_onesignal_default . @Yokesh 图标必须命名为ic_stat_onesignal_default是正确的。 The location of the file however depends on the fork of Cordova you are using.但是,文件的位置取决于您使用的 Cordova 分支。

For Cordova CLI or Ionic the path is:对于 Cordova CLI 或 Ionic,路径是:

<project-root>/platforms/android/res/drawable-[SIZE_NAMES]/

PhoneGap Build (PGB): PhoneGap 构建(PGB):

<project-root>/locales/android/drawable-[SIZE_NAMES]/

Replace [SIZE_NAMES] with hdpi , xhdpi , xxhdpi , xxxhdpi creating one for each name.[SIZE_NAMES]替换为hdpixhdpixxhdpixxxhdpi为每个名称创建一个。 Four folders will be created in total.总共将创建四个文件夹。

See OneSignal's Customize Notification Icons guide for more details.有关更多详细信息,请参阅 OneSignal 的自定义通知图标指南。

This link ultimately helped me: https://documentation.onesignal.com/docs/customize-notification-icons这个链接最终帮助了我: https : //documentation.onesignal.com/docs/customize-notification-icons

You need to add ic_stat_onesignal_default.png in the appropriate size to each of the resource folders where icons are stored.您需要将适当大小的 ic_stat_onesignal_default.png 添加到每个存储图标的资源文件夹中。 For cordova this was:对于科尔多瓦来说,这是:

platforms/android/res/drawable-hdpi平台/android/res/drawable-hdpi

platforms/android/res/drawable-ldpi平台/android/res/drawable-ldpi

platforms/android/res/drawable-mdpi平台/android/res/drawable-mdpi

platforms/android/res/drawable-xhdpi平台/android/res/drawable-xhdpi

Here is official documentation about notification icons:这是关于通知图标的官方文档:

https://documentation.onesignal.com/docs/customize-notification-icons https://documentation.onesignal.com/docs/customize-notification-icons

The normal vector asset or png file in drawable is not working. drawable 中的法线矢量资产或 png 文件不起作用。 Even mipmap also.连mipmap也。 You need to create custom drawable with different size configurations.您需要创建具有不同大小配置的自定义 drawable。

Use these directories for Native Android :将这些目录用于原生 Android

res/drawable-mdpi/ (24x24)
res/drawable-hdpi/ (36x36)
res/drawable-xhdpi/ (48x48)
res/drawable-xxhdpi/ (72x72)
res/drawable-xxxhdpi/ (96x96)
res/drawable-xxxhdpi/ (256x256) (Large Icon)

And for Cordova :对于科尔多瓦

<project-root>/platforms/android/app/src/main/res/drawable-mdpi/ (24x24)
<project-root>/platforms/android/app/src/main/res/drawable-hdpi/ (36x36)
<project-root>/platforms/android/app/src/main/res/drawable-xhdpi/ (48x48)
<project-root>/platforms/android/app/src/main/res/drawable-xxhdpi/ (72x72)
<project-root>/platforms/android/app/src/main/res/drawable-xxxhdpi/ (96x96)
<project-root>/platforms/android/app/src/main/res/drawable-xxxhdpi/ (256x256) (Large Icon)

Note: use the same name file in each dir.注意:在每个目录中使用相同名称的文件。

Here consider this link. 在这里考虑这个链接。 Please try to search first if you dont find any useful info then consider posting a question there are already questions answered.如果您没有找到任何有用的信息,请先尝试搜索,然后考虑发布已经回答的问题。

NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(this) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(R.mipmap.logo). NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(this) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setSmallIcon(R.mipmap.logo)。 setLargeIcon(R.mipmap.logo1) setLargeIcon(R.mipmap.logo1)

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

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