Ionic 2:本地通知图标

时间:2017-02-08 15:26:28

标签: javascript typescript notifications ionic2

我使用此插件进行本地通知: https://github.com/katzer/cordova-plugin-local-notifications/wiki/03.-Installation

我希望在通知中有一个特定的图标。它位于我的/ www / assets / images /文件夹中。

我尝试这种方式但它不起作用,我有一个带铃铛的方形图标:

public schedule() {
    cordova.plugins.notification.local.schedule({
      title: "New Message",
      message: "Hi, are you ready? We are waiting.",
      sound: null,
      at: new Date(new Date().getTime() + 5 * 1000),
      icon: 'file://assets/images/logo2.png'
    });
  }

有人可以告诉我我必须写的路径类型吗?我输了。

5 个答案:

答案 0 :(得分:6)

对于离子2插件的本地推送通知,您可以设置如下图标。这里icon.png将从android的可绘制文件夹中获取。并且您可以通过在android平台部分下的配置文件中添加以下内容来配置离子来复制要在可绘制文件夹中复制的本地图像文件。

<platform name="android">
<resource-file src="resources/android/icon/icon.png" target="res/drawable/icon.png"/>
</platform>


this.localNotifications.schedule({
          id: 1,
          title: data.title,
          text: data.body,
          data: data,
          icon: "res://icon.png",
          smallIcon:"res://icon.png"
        });

答案 1 :(得分:4)

如果您唯一的问题是Android上的通知图标正确显示,则以下内容适用于我 - 使用 drawable-xhdpi-icon 图标(尺寸 96x96 ),将其重命名为 icon.png 并将其放置在两个位置:

  • / src / assets / img
  • /平台/机器人/ RES /可绘

drawable 文件夹是一个新文件夹,可以通过复制 platforms / android / res / mipmap-xhdpi <来创建/ strong>手动或借助钩子 platforms / android / res / drawable 。 在您的代码中,本地地理围栏通知的引用如下:

smallIcon: 'res://icon',
icon: 'file://assets/img/icon.png'

如果 ionic cordova资源 是问题的一部分,您可以通过获取最大的图标并在调整大小工具的帮助下进行自己的一次性设置比如resizeimage.net,为iOS和Android创建一组图标。 这里的Excel https://github.com/dovk/howto_resources-folder列出了要创建的.png文件的大小和名称。然后将它们放在各自的资源文件夹中,就像 ionic cordova resources 那样 - 例如在 resources / android / icon,resources / ios中/ splash 等等。 如果您这样做,那么 离子cordova平台添加android 离子cordova平台添加ios 不应再使用,这也是 离子cordova资源 - 你需要做的是 cordova平台添加 (没有<在开始时强> 离子

答案 2 :(得分:1)

我找到了解决方案:

我在/ platforms / android / res /中创建一个名为“drawable”的新文件夹 我将我的图像放在名为“ic_notifications.png”和“ic_notifications_small.png”的新文件夹中。

在我编写的代码中

cordova.plugins.notification.local.schedule({
      id: 2,
      title: "Notification",
      message: "Retour à l'application",
      sound: null,
      at: new Date(new Date().getTime() + 5 * 1000),
      icon: 'ic_notifications',
      smallIcon: 'ic_notification_small'
    });

它有效!

答案 3 :(得分:0)

在 AndroidManifest.xml 中添加以下元数据即可使用。

 <application
    android:name="xxxxxx"
        android:label="xxxxxx"
        android:icon="@mipmap/ic_launcher"
        
        >

       <meta-data
                android:name="your_apps_bundle_id.default_notification_icon"
                android:resource="@drawable/ic_notif" />

......

答案 4 :(得分:-1)

在不添加图像文件名扩展名的情况下,提供如下图像路径 LocalNotifications.schedule({ id: 1, title: "Notification Title", text: "Notification Text", icon: 'assets://images/image_name' });

相关问题