Cordova-plugin-local-notifications: Why Does Android Not play sound? Help Me, Please.

Created on 21 Nov 2017  路  9Comments  路  Source: katzer/cordova-plugin-local-notifications

The sound file is stored in the path: www/resource/media/beep.wav .
And the code is following:
var nopts = {
id: 1,
title: 'First row of the notification',
text: 'Second row of the notification',
// at: _5_sec_from_now,
at: null,
// at: new Date(), // now, // Default: now ~ new Date()
// firstAt: new Date() , // now, // Default: now ~ new Date()
every: 'year', // Default: 0 // second, minute, hour, day, week, month or year
sound: 'www/resource/media/beep.wav',
badge: 7
};
cordova.plugins.notification.local.schedule(nopts);

In a result, the iOS can play the sound, and the android can NOT play the sound. Why?

Another question is that if remove the every parameter, notification is NOT be scheduled. I need ONLY ONE notification . What's more, android is NOT notified right now but delayed notified.

How to fixed these two problems? Help Me. Please.

Most helpful comment

Good day ! I am using cordova-plugin-local-notification version 0.9.0-beta.2 but on Android dose not play sound. Help please !

        win.cordova.plugins.notification.local.schedule({
          id: Math.floor(Math.random()),
          title: 'Mobile',
          text: 'Updating Complete!',
          trigger: { in: 1, unit: 'second' },
          sound:  'res://platform_default' 
          icon: 'file://assets/icon/download.png',
          smallIcon: 'file://assets/icon/download.png'
        });

All 9 comments

Please update to the latest version and use new configs (trigger: { }).

Yes. I do: cordova plugin add cordova-plugin-local-notification
and do: cordova plugin ls
and it displays: cordova-plugin-local-notification 0.8.4 "LocalNotification"
and the trigger:{} , the trigger is invalid.

The lastest version is 0.8.4. it is right?

nope, please use

cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git

latest version is 0.9.0-beta.1

I have added the l=0.9.0beta.1 version. But, the following code does not work:
var sound = 'file://resource/media/beep.wav';
var nopts = {
// id: 1,
title: 'First row of the notification',
text: 'Second row of the notification',
// at: _5_sec_from_now,
// at: null,
// at: new Date(), // now, // Default: now ~ new Date()
// firstAt: new Date() , // now, // Default: now ~ new Date()
// every: 'year', // Default: 0 // second, minute, hour, day, week, month or year
trigger: { in: 1, unit: 'hour' },
sound: sound, // Default: res://platform_default
badge: 7
};

  cordova.plugins.notification.local.schedule(nopts);

@nodejscss Android cannot play .wav files. In practice you may end up using different audio files per platform like in the sample app.

I change the wav to .mp3 for android , but it still does NOT work too.
There are 2 files in the www/resource/media/ path : beep.mp3 and beep.wav .

var sound = is_android ? 'file://resource/media/beep.mp3' : 'file://resource/media/beep.wav';
var nopts = {
id: 1,
title: 'First row of the notification',
text: 'Second row of the notification',
trigger: { in: 1, unit: 'hour' },
sound: sound, // Default: res://platform_default
badge: 7
};
cordova.plugins.notification.local.schedule(nopts);

is_android = !!window.device && window.device.platform.toLowerCase() === 'android';

Yes. It works. I change
trigger: { in: 1, unit: 'hour' }
to
trigger: { in: 1, unit: 'second' }

Thank you very much.

Good day ! I am using cordova-plugin-local-notification version 0.9.0-beta.2 but on Android dose not play sound. Help please !

        win.cordova.plugins.notification.local.schedule({
          id: Math.floor(Math.random()),
          title: 'Mobile',
          text: 'Updating Complete!',
          trigger: { in: 1, unit: 'second' },
          sound:  'res://platform_default' 
          icon: 'file://assets/icon/download.png',
          smallIcon: 'file://assets/icon/download.png'
        });
Was this page helpful?
0 / 5 - 0 ratings