Skip to content Skip to sidebar Skip to footer

Playing Default Android Sound Of Button, Clicking Ontouch() Method

In my android app I have some buttons, that should work with onTouch() method, course I need to change button's text, when finger in ACTION_DOWN position. But this buttons should t

Solution 1:

Use this code in your onTouch() method:

view.playSoundEffect(android.view.SoundEffectConstants.CLICK);

If you are simply looking for a preset Android sound then it's better to use this functionality that's provided to you for free by the framework. Doing anything else, unless necessary for customization, would simply result in you working against the framework instead of working with it.

Solution 2:

Use default sounds from /system/media/audio/

MediaPlayer or SoundPool will help to implement playback.

Solution 3:

Consider using view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);.

It will do both: playing the default sound and vibrate if the user has it enabled in the global settings.

Post a Comment for "Playing Default Android Sound Of Button, Clicking Ontouch() Method"