urbanairship / urbanairship-cordova

Urban Airship integration with Apache Cordova
https://docs.airship.com/platform/mobile/setup/sdk/cordova/
Other
142 stars 149 forks source link

Default Notification Sound #277

Closed gonzalovinas closed 5 years ago

gonzalovinas commented 5 years ago

Hi there! I would like to change default notification sound or even better use the device (phone) available sounds. It has to be a "per device" setting...

thanks in advance

rlepinski commented 5 years ago

iOS you can control the sound through the push API (and composer). If you use the sound default it will play the device sound. You can also include other sound files in your app bundle and use those as names in the API.

Android is sort a mess in terms of sound support. We have various support depending on the device API level.

Android 8.0+ When they introduced notification channels in Android 8.0, we can no longer support set the sound per notification. Instead we can only set the notification channel that is configured with a sound, vibrate, lights settings. The channels have to be predefined, but once they are you can set the channel to be used on a notification through the push api.

Pre Android 8.0 We have full control over the notification in the SDK, so we can support sound per notification and even provide an an option in the push API.

We are thinking through how to provide a unified APIs that work across all devices for Android, but that wont be ready for a few more months. Most likely we will provide a compat notification channel API that we can apply to older Android devices. We have a few tickets to provide notification channel APIs in cordova so the app can generate them without using any native code.

For now, you will most likely have to create channels for newer android devices in java, then when sending the push set both the channel and the sound in the push api to make it work across all devices.

gonzalovinas commented 5 years ago

Sorry if my question misled you. I'll try to clarify....

I'm asking what to do to have same feature as Gmail, Facebook or Whatsapp in-app-way to change default notification sound using stored sounds/ringtones in the phone itself.

Maybe using this: https://github.com/TongZhangzt/cordova-plugin-native-ringtones or better using native phones OS screen...

Thanks!

gonzalovinas commented 5 years ago

Looking at the UAShip configuration file... there is an option to change default notification sound...

What I need then is able to set this at runtime...

Kinda #235 #234

rlepinski commented 5 years ago

@gonzalovinas That will only work on Android pre 8.0. My original post is still accurate.

On iOS, remote notifications require the sound to be defined in the payload. Android pre 8.0 you can use that since we can control it per push, but Android 8.0+ requires the channel with the sound to be set up ahead of time.

gonzalovinas commented 5 years ago

I found a way, modifying urbanariship-android library in the PushMessage.java @ public Uri getSound(@NonNull Context context) method. Originally it searches "EXTRA SOUND" in android.resource:// but it can be changed to phones' tones files at: content://media/internal/audio/media/ or whatever you want.

Are you interested in me doing a pull request on this?

rlepinski commented 5 years ago

@gonzalovinas We are looking for a difference solution. The tones for the device may or may not exist so its better to package the sounds with the app if you want to depend on them.