Android Code Snippet [Notification Builder] How to add a custom sound from File.DirAssets

Hi everyone!!!


I want to share with you my solution, using the Notification Builder (Thanks to @barx for this awesome library <3 ), to play a custom sound from your DirAssets folder. I did it because this method use the notification volume for this sound (instead of the Soundpool solution, that use the media volume).

B4X:
File.Copy(File.DirAssets,"you-have-new-message.mp3",File.DirDefaultExternal,"you-have-new-message.mp3")
   
Dim path_to_file As String = ""
   
path_to_file = "file://"&File.DirDefaultExternal&"/you-have-new-message.mp3"
   
notify.CustomSound = path_to_file


If you see, i just add my custom sound into the File.DirAssets, then i copy the same file into the File.DirDefaultExternal with the instruction "File.Copy".

The next step was build the entire path to the file. When you string is ready, you can use it on the method "CustomSound" :D! .

Regards from Chile and i hope you find it useful!!!.

- Carlos Huerta
 
Top