How can I set sound for notification for my android application. In my application notification will be shown after 30 seconds. I want to give options for this alerts such as silent mode, vibration mode and an option to select from the available tones from the device. I am using the preference screen to show the settings menu. I want to to set the notification ring type application specific. Is there any way to establish this..
Setting sound for notification
16.6k Views Asked by Dijo David At
2
There are 2 best solutions below
0
David Manpearl
On
How to Set a Custom Sound for an Android Notification
Place a .mp3 or .wav file in your res/raw directory such as "notification_sound.mp3" as in the example below (the filename must not use capital letters).
Set the Notification.sound when you create your Notification, like this:
final int iconResId = R.drawable.my_icon;
final int soundResId = R.raw.notification_sound;
final Notification notification =
new Notification(iconResId, tickerText, System.currentTimeMillis());
final String packageName = context.getPackageName();
notification.sound =
Uri.parse("android.resource://" + packageName + "/" + soundResId);
Optionally, add vibration to your Notification:
notification.defaults = Notification.DEFAULT_VIBRATE;
Related Questions in ANDROID
- Creating global Class holder
- Flutter + Dart: Editing name of a tab shows up a black screen
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Sdk 34 WRITE_EXTERNAL_STORAGE not working
- ussd reader in Recket Native module
- Incorrect display of LinearGradientBrush in IOS
- The Binary Version Of its metadata is 1.8.0, expected Version is 1.6.0 build error
- I can't make TextInput to auto expand properly in Android
- Creating multiple instances of a class with different initializing values in Flutter
- How to create a lottie animation
- making android analyze with coverity sast tool
- Flutter plugin development android src not opening after opening example
- I initialize my ViewModel in the Activity with several fragments as tabs, but the fragments(tabs) return null for the updated livedata
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How I can use the shared preferences class?
Related Questions in AUDIO
- how to play a sounds in c# forms?
- Winsound not working isn't working at all
- Ringing noise overpowering voice / Recording audio with Max 9814 microphone on Raspberry pi pico using ADC Pin / Circuitpython
- How to take first x seconds of Audio from a wav file read from AWS S3 as binary stream using Python?
- gluon attach audio doesn't play any sound on android
- Implementing trim and fade filters with ffmpeg - MP3
- Unable to set device connection state as INPUT device type is none
- Is there a way to differentiate music and talking from a video?
- How to concatenate audio tracks and make them start a certain moment using Python?
- Combine two audio in different languages to one natural sounding
- STM32 - Serial Audio Interface (SAI) - dual data line transmit possible?
- playing mp3 downloaded via curllib gets cut short
- How to stream PCM audio to a speakers both on mac and linux in Node.js?
- Scikit-Maad -From the function rois.find_rois_cwt, I want to get a csv of the outputs so I can do my own analysis on it
- Using MediaPlayer slows down SoundPool sound effect
Related Questions in SHAREDPREFERENCES
- How I can use the shared preferences class?
- Flutter Theme Flickers Briefly Before Switching to Light Mode
- Some users facing issues changing app language in Android app
- Null point in sharedperfernces of subclass
- Material Toggle Button SharedPreferences
- Availability of SharedPreferences to multiuser-aware android apps
- How can I store the set pattern lock in flutter?
- shared_preferences in Flutter. 10 packages have newer versions incompatible with dependency constraints
- Capacitor Preferences Plugin - Can get Capacitor/Console value but DevTools value is null
- Do I have to use Device Protected Storage Context to create an instance of SharedPreferences file that has been moved to device protected storage?
- Which is more secure: EncryptedSharedPreferences or storing directly in KeyStore?
- NullPointerException on MainActivity with SharedPreferences, 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- I'm having a complex issue with my app using Flutter
- Unsafe cryptographic encryption patterns" - How I can fixed this error?
- i cant change the color of a view widget inside settings on a settings button
Related Questions in RINGTONE
- I am unable to set ringtone using activity in android studio?
- How to set ringtone in Android from my activity on upcoming Android 14 (UPSIDE_DOWN_CAKE API 34)?
- The application does not work on newer versions of Android (version 9 and above)
- How to retrieve the original default ringtone that came with the Android device?
- Can I Stop Original ringtone and play my custom ringtone time of incoming call in swift?
- How to play system sound in flutter web?
- set custom Sound from only my application in push notification android
- How to make IN_CALL_SERVICE_RINGING work?
- How to get ringtone path in android
- Alarm manager or sound notification are not working in release mode Android 13
- How to use media player for play a ringtone while one signal notification received in android
- How to make a alarm open a new activity android studio kotlin
- Setting ringtone to different sim cards Android
- Ringtone not playing on certain Samsung devices with Android 11
- java.lang.IllegalArgumentException: Invalid column: _data
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
http://developer.android.com/reference/android/app/Notification.Builder.html#setSound(android.net.Uri)
Use a ringtone preference in the preference activity to get the URI of the selected sound.