react-native-notification-sounds icon indicating copy to clipboard operation
react-native-notification-sounds copied to clipboard

default sound

Open martinattin opened this issue 3 years ago • 5 comments

I need to show the default notification sound which is selected in the device. Is there any way to get the default notification sound.

martinattin avatar Jun 20 '21 16:06 martinattin

Did you figure anything out?

marcjulianfleck avatar Sep 30 '21 13:09 marcjulianfleck

how to get default sound of ringtone?

mdtechcs avatar Oct 05 '21 06:10 mdtechcs

Yes , It is only possible to get default device sound on android. On IOS we don't have acess to device ringtones and alerts. I had to fork the package and add a function on android to get device default alert sound . @ReactMethod public void getDefaultSound(final Promise promise) { try { Uri defautNotification = RingtoneManager.getActualDefaultRingtoneUri(this.reactContext, RingtoneManager.TYPE_NOTIFICATION); String result = java.net.URLDecoder.decode(String.valueOf(defautNotification), StandardCharsets.UTF_8.name()); promise.resolve(result); } catch (Exception e) { e.printStackTrace(); } }

the above function will return the url. We will need to format this url to get the name.

The JS code for formatting url is

if (url) { const soundName = url.split('/').pop().split('.')[0]; //Different android OS has different formatting on sound URL, Including a formatting for certain android devices if (soundName.includes('?')) { const formattedName = soundName.substring( soundName.indexOf('=') + 1, soundName.lastIndexOf('&'), ); return formattedName; } return soundName; }

My forked liabrary is [https://github.com/martinattin/react-native-notification-sounds.git]

You can check commit history and make those changes in your liabrary to acheive this functionality.

martinattin avatar Oct 05 '21 11:10 martinattin

To play the default sound, just call playSampleSound() with no parameters. This only works for Android.

saadqbal avatar Feb 09 '22 06:02 saadqbal

To work with the default value you have to pass it like this: playSampleSound([])

devsfer1 avatar Dec 06 '22 16:12 devsfer1