question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android 8.0 custom notification sound

See original GitHub issue

Provide a general summary of the issue.

Your Environment

  • Plugin version: 0.9.0-beta.2
  • Platform: Android
  • OS version: 8.0.x
  • Device manufacturer / model: Samsung Galaxy s8
  • Cordova version (cordova -v): 4.2.1
  • Cordova platform version (cordova platform ls): 7.1.4
  • Plugin config: none
  • Ionic Version: 3.9.2

Expected Behavior

Using:

this.localNotifications.schedule({
                    id: 1,
                    text: 'You have arrived',
                    sound: 'file://assets/sounds/alerts/arrival.mp3',
                    data: { secret: 'hellloo' },
                    vibrate: true
                });

I want to display a notification with a custom sound Located in src/assets/sounds/alerts/...

Actual Behavior

I’ve tried every possible filepath (I think) however it still plays the default Samsung Galaxy s8 notification sound.

Context

Explained above.

Debug logs

Logcat output:

02-28 17:38:06.354  3779  3779 D EdgeLightingManager: showForNotification : isInteractive=true, isHeadUp=false, color=0, sbn = StatusBarNotification(pkg=io.ionic.starter user=UserHandle{0} id=1 tag=null key=0|io.ionic.starter|1|null|10203: Notification(channel=default-channel-id pri=0 contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x11 color=0x00000000 number=0 vis=PUBLIC semFlags=0x0 semPriority=0 semMissedCount=0))
02-28 17:38:06.354  3779  3779 D EdgeLightingPolicyManager: putNotification tickerText:true,titleText:true,text:true,sub:falsecn= + null
02-28 17:38:06.354  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: updateNotificationData put :0|io.ionic.starter|1|null|10203,size=7
02-28 17:38:06.354  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|io.ionic.starter|1|null|10203:NotificationData time=1551371886354,
02-28 17:38:06.354  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|android|40|null|1000:NotificationData time=1551371251595,
02-28 17:38:06.355  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|com.rolflex.mobCSRApp|6|null|10156:NotificationData time=1551291051811,
02-28 17:38:06.355  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|com.wssyncmldm|1|null|1000:NotificationData time=1551349895823,
02-28 17:38:06.355  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|com.google.android.apps.maps|g:atn_group:NotificationData time=1551371775363,
02-28 17:38:06.355  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|com.rolflex.mobCSRApp|-574543954|null|10156:NotificationData time=1551291051833,
02-28 17:38:06.355  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|com.android.vending|874755343|null|10043:NotificationData time=1551314492705,
02-28 17:38:06.355  3779  3779 D EdgeLightingPolicyManager.NotificationGroup: 0|com.android.settings|9|null|1000:NotificationData time=1550852356484,
02-28 17:38:06.355  3779  3779 D EdgeLightingManager: showForNotificationScreenOn : return false by isAcceptableApplication.
02-28 17:38:06.365  3779  3779 I AccessibilityManagerService: semOnLightNotification(null), bIsFlashOn : false
02-28 17:38:06.372  4196  4196 D StatusBar: addNotification key=0|io.ionic.starter|1|null|10203 fullscreen:false
02-28 17:38:06.460  3426 15233 V NuPlayer: onSourceNotify() kWhatFlagsChanged  FLAG_CAN_PAUSE: 1  FLAG_CAN_SEEK_BACKWARD: 1 
02-28 17:38:06.461  3426 15233 V NuPlayer: NuPlayer::onSourceNotify Source::kWhatPrepared source: 0xe7d6dc40

I’ve noticed that ‘sound = null’ is being logged, which is kind of weird. Thanks in advance.

With kind regards,

Jonah

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:23

github_iconTop GitHub Comments

3reactions
talal-alkaremiecommented, Mar 3, 2019

I use this version ==> https://github.com/Steffaan/cordova-plugin-local-notifications for my application it works perfectly on Android 7+ and here is the code I use

var sound = device.platform != 'iOS' ? 'file://audio/adhan.mp3' : 'content://audio/adhan.mp3';
cordova.plugins.notification.local.schedule({
			id:1,
			channel: 'myChannel',
			title: 'my title',
			text:'place here any text',
			at: new Date(),
			sound: sound,
			priority:1,
			count:1
		});

hope this help

2reactions
caioschwartzcommented, May 8, 2020

@talhaZahidch, don’t forget to consider, as i said before, that the katzer/cordova-plugin-local-notifications din’t work for me. I’ve used the Steffaan version.

With the Steffaan version i did:

A. Put a .mp3 and .caf file in the root of the project

B. At config.xml

  1. Add <plugin name="https://github.com/Steffaan/cordova-plugin-local-notifications" /> 2 Add <resource-file src="???.mp3" target="app/src/main/res/raw/???.mp3" /> inside <platform name="android">
  2. Add <resource-file src="???.caf" target="www/res/???.caf" /> inside <platform name="ios">

C. Call the method

cordova.plugins.notification.local.schedule( { channel: 'ChannelName', color: '#16A7E0', icon: 'res://icon', id: 3, priority: 2, smallIcon: 'res://ic_dialog_alert', sound: device.platform.toLowerCase() === 'android' ? "res://???.mp3" : "res://???.caf", title: 'Warning', text: 'Time is running out', trigger: { at: dateToPopNotification }, vibrate: true } );

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set custom ringtone in android Oreo 8.0 device
Change Default Notification Sound in Android Oreo 8.0. Settings > Sound > Advanced > Default notification sound > + Add ringtone > Select...
Read more >
How to set notification with custom sound in android 8.0?
I have tried to set the custom notification sound it works fine below Oreo(8.0) devices but in Oreo device it doesn't trigger custom...
Read more >
Customize Notification Sounds on Android Oreo - VisiHow
Set Custom Ringtones, Notification Sounds and Alarms · 1. On the home screen, tap or swipe up from the arrow to access your...
Read more >
4 Ways to Add Notification Sounds on Android - wikiHow
1. Save a custom sound to your Android. There's a variety of ways to find and save custom sounds. You can download them...
Read more >
Custom notification sound for Android 8+ devices - Pushwoosh
Starting from Android 8, in order to send the notification with your own custom sound, you need to create its own Notification Channel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found