Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default sound #15

Open
martinattin opened this issue Jun 20, 2021 · 5 comments
Open

default sound #15

martinattin opened this issue Jun 20, 2021 · 5 comments

Comments

@martinattin
Copy link

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

@marcjulianfleck
Copy link

Did you figure anything out?

@mdtechcs
Copy link

mdtechcs commented Oct 5, 2021

how to get default sound of ringtone?

@martinattin
Copy link
Author

martinattin commented Oct 5, 2021

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.

@saadqbal
Copy link
Owner

saadqbal commented Feb 9, 2022

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

@saadqbal saadqbal closed this as completed Feb 9, 2022
@saadqbal saadqbal reopened this Feb 9, 2022
@devsfer1
Copy link

devsfer1 commented Dec 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants