In the previous series of tutorial we have seen how to create notification both in kotlin and java
In this tutorial we will see playing notification sound different resources( audio file kept different resource like from project "res/raw" and hosted in CDN ) .
Kotlin
1. Default
2. Resource
3. Remote CDN
To play notification sound we need Uri of the file hosted .
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) val r = RingtoneManager.getRingtone(context, defaultSoundUri) r.play()
2. Resource
Make Sure you have kept custom_sound audio inside "res/raw" folder
val rawPathUri: Uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.custom_sound); val r = RingtoneManager.getRingtone(context, rawPathUri) r.play()
3. Remote CDN
val cdnPathUri: Uri = Uri.parse("https://www.myinstants.com/media/sounds/beeper_emergency_call.mp3") val r = RingtoneManager.getRingtone(context, cdnPathUri) r.play()
JAVA
1. Default
2. Resource
3. Remote CDN
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(MainActivity.this, defaultSoundUri); r.play();)
2. Resource
Make Sure you have kept custom_sound audio inside "res/raw" folder .
Uri rawPathUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.custom_sound); Ringtone r = RingtoneManager.getRingtone(MainActivity.this, rawPathUri); r.play();
3. Remote CDN
Uri cdnPathUri = Uri.parse("https://www.myinstants.com/media/sounds/beeper_emergency_call.mp3"); Ringtone r = RingtoneManager.getRingtone(MainActivity.this, cdnPathUri); r.play();
1 comment:
volume setting on kotlin
Post a Comment