Ionic OneSignal通知图标和声音

时间:2018-12-16 02:31:58

标签: android cordova ionic-framework

我通过OneSignal插件在我的应用中增加了通知,我想自定义通知的图标和声音,我遵循了文档,但是没有用。

我做错了什么? 这是我的config.xml的打印文件

enter image description here

代码config.xml:

<platform name="android">
    <allow-intent href="market:*" />
    <resource-file src="resources/android/sound/open-ended.mp3" target="platforms/android/res/raw/open-ended.mp3" />
    <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
    <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
    <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
    <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
    <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
    <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
</platform>

app.component.ts:

this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
this.oneSignal.handleNotificationReceived().subscribe(data => {
  data.payload.sound = 'open-ended',
  data.payload.smallIcon = 'drawable-hdpi-icon'
});
this.oneSignal.handleNotificationOpened().subscribe(() => {
  // do something when a notification is opened
});
this.oneSignal.endInit();

我正在使用cordova-android:7.1.4和onesignal-cordova-plugin:2.4.5

1 个答案:

答案 0 :(得分:0)

<resource-file src="resources/android/sound/mysound.wav" target="app/src/main/res/raw/mysound.wav" />

这是我放置的方式及其工作原理。对于Android 8+,您需要在onesignal设置中创建通知类别