katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

Custom Sound not playing in Android version 8 (Oreo). Plays default sound for local notification #1605

Closed swapnilghadge8149 closed 2 weeks ago

swapnilghadge8149 commented 6 years ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.

Your Environment

Expected Behavior

Tell us what should happen .wav file is stored in local file storage. But sound is not playing for local notification. It plays default notification sound.

Actual Behavior

It plays default notification sound. Tell us what happens instead The .wav file should be played as local notification sound.

Steps to Reproduce

file:///storage/emulated/0/ActiveShooter.wav Reproduce this issue; include code to reproduce, if relevant this.localNotifications.schedule({ id: id, text: msg, sound: "file:///storage/emulated/0/ActiveShooter.wav" });

  1. ...
  2. ...
  3. ...
  4. ....

Context

What were you trying to do?

Debug logs

Include iOS / Android logs

RainerAppel commented 6 years ago

Same here. Palying custom sound files for notifications does not work any more. It worked with plugin-local-notifications V 0.8 and android target version 23. After updating to plugin version 0.9.0-beta.3 and android target version 26 I only hear the default sound when my notifications are triggered.

sachinGAcharya commented 6 years ago

same problem here. Anyone found the solution for this?Please help me.Not able to play custom notification sound on android O.

talal-alkaremie commented 6 years ago

I am facing the same problem on android 8

sachinGAcharya commented 6 years ago

I got the solution for local notification on android 8 Its working .Posting here so that it could help someone,

ionic cordova plugin add cordova-plugin-local-notification@0.9.0-beta.3 npm install --save @ionic-native/local-notifications cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION=26.0.1 ionic cordova platform add android@6.3.0

Use this for getting message on local notification and open patform/android/src/de/Builder.java

replace if (sound != Uri.EMPTY && !isUpdate()) { builder.setSound(sound); } this with

try {

    Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), sound);
    r.play();
  } catch (Exception e) {
    e.printStackTrace();
  }
coffeverton commented 6 years ago

@sachinGAcharya I found the code you mentioned to replace in three different places. In two of them, it did nothing. In one (platforms/android/app/src/main/java/de/appplant/cordova/plugin/notification/Builder.java), it throwed an error during cordova run:

error: cannot find symbol Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), sound); ^ symbol: class Ringtone location: class Builder

And it did not work.

coffeeexistence commented 6 years ago

@sachinGAcharya that does not look like a suitable solution since that looks like it'll play the notification sound immediately.

Logcat gives me the following warning when I set the sound property:

Use of stream types is deprecated for operations other than volume control
See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
MInesGomes commented 5 years ago

Did you found a solution @swapnilghadge8149 @katzer ? The custom sound is working on Nougat, but not in Pie.

I have seen this : https://stackoverflow.com/questions/50567164/custom-notification-sound-not-working-in-oreo

MInesGomes commented 4 years ago

I set here also this problem https://github.com/ionic-team/ionic/issues/19696

and it seems missing the "channel" as described here: https://distriqt.github.io/ANE-PushNotifications/m.FCM-GCM%20Payload

Sounds on individual notifications were deprecated in Android O (API 26). You now have to set them on a channel.

theavijitsarkar commented 4 years ago

Any update on this?

MInesGomes commented 4 years ago

@theavijitsarkar this is working for me https://github.com/Steffaan/cordova-plugin-local-notifications.git

theavijitsarkar commented 4 years ago

No luck so far. I have put the sound file in www/static/alarm1.wav. Also, I dont get the icon either. Device is One plus 7T Android 10 Can you help?

CODE

{
            channel: 'channel',
            channelDescription : "This channel reminds you to XXXX",
            id : 1,
            title: 'Its time',
            text : Did you",
            actions: [{ id: 'yes', title: 'Yes' }],
            launch :true,
            icon :  cordova.file.applicationDirectory+"www/static/cordova-android-icon.png",
            smallIcon: 'res://calendar',
            sound : cordova.file.applicationDirectory+"www/static/alarm1.wav"
        }

LOGCAT

   Asset  E  File not found: /android_asset/www/static/alarm1.wav
           Notification  W  Use of stream types is deprecated for operations other than volume control
                         W  See the documentation of setSound() for what to use instead with android.media.Audi
                            oAttributes to qualify your playback use case
     CordovaWebViewImpl  D  >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("trigger",{"sou
                            nd":"file:\/\/\/android_asset\/www\/static\/alarm1.wav","title":"test1","channel":"
                            test","actions":[],"attachments":[],"autoClear":true,"clock":true,"defaults":0,"gro
                            upSummary":false,"id":0,"launch":true,"led":{"color":"#FF00FF","on":500,"off":500},
                            "lockscreen":true,"number":0,"priority":2,"progressBar":{"enabled":false,"value":0,
                            "maxValue":100,"indeterminate":false},"silent":false,"smallIcon":"res:\/\/icon","te
                            xt":"","timeoutAfter":null,"trigger":{"type":"calendar"},"vibrate":true,"wakeup":tr
                            ue,"when":0,"meta":{"plugin":"cordova-plugin-local-notification","version":"0.9-bet
                            a.3"}},{"event":"trigger","foreground":true,"queued":false,"notification":0}))
                         D  >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("add",{"sound":
                            "file:\/\/\/android_asset\/www\/static\/alarm1.wav","title":"test1","channel":"test
                            ","actions":[],"attachments":[],"autoClear":true,"clock":true,"defaults":0,"groupSu
                            mmary":false,"id":0,"launch":true,"led":{"color":"#FF00FF","on":500,"off":500},"loc
                            kscreen":true,"number":0,"priority":2,"progressBar":{"enabled":false,"value":0,"max
                            Value":100,"indeterminate":false},"silent":false,"smallIcon":"res:\/\/icon","text":
                            "","timeoutAfter":null,"trigger":{"type":"calendar"},"vibrate":true,"wakeup":true,"
                            when":0,"meta":{"plugin":"cordova-plugin-local-notification","version":"0.9-beta.3"
                            }},{"event":"add","foreground":true,"queued":false,"notification":0}))
  SystemWebChromeClient  D  webpack:///./src/js/notificationCenter.js?: Line 115 : Triggered 
BalanaguYashwanth commented 4 years ago

Any sustainable solution guys to play custom notification in android version more than oreo ???

BalanaguYashwanth commented 4 years ago

I solved the issue it is very simple

https://medium.com/@nitishk72/flutter-local-notification-1e43a353877b Follow this above post and then, From the above post in the place of 'method 1' replace the code(below) like

Future showNotification() async { var androidPlatformChannelSpecifics = new AndroidNotificationDetails( 'your channel id', 'your channel name', 'your channel description', sound: RawResourceAndroidNotificationSound('alert'), importance: Importance.Max, priority: Priority.High); var iOSPlatformChannelSpecifics = new IOSNotificationDetails(sound: "alert.aiff"); var platformChannelSpecifics = new NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.show( 0, 'Safety app', 'Requesting to maintain social distance', platformChannelSpecifics, payload: 'Please maintain the social distance', ); print("result:Notification came "); }