Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable default sound effects for all my application or activity

Tags:

android

In my application I am using sound pool for the button click audio effect. The problem is that if in the device's settings "Audible selection" is ticked, then my buttons will produce two sounds: the system one and my one at the same time.

It seems that if in each button properties I set "Sound Effects Enabled" to false, the system sound is not heard any more. But I have many buttons across a dozen of activities, plus I am adding a matrix of buttons in code, so it is rather inconvenient to set "Sound Effects Enabled" to false manually for each one of them. Not sure how I do this in code..

Is there a more global way to stop "Audible selection" in my application or at least for the one activity?

like image 791
Lumis Avatar asked Feb 16 '11 22:02

Lumis


4 Answers

Create a theme file "res/values/styles.xml"

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppBaseTheme" parent="android:Theme.Black.NoTitleBar">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:soundEffectsEnabled">false</item>
</style>

</resources>

And then reference to it in your "AndroidManifest.xml"

<application
    ...
    android:theme="@style/AppTheme" >
like image 167
David Douglas Avatar answered Oct 30 '22 07:10

David Douglas


I just had the same problem for my application. I was able to turn off sound feedback globally by putting android:soundEffectsEnabled=false in a theme.

like image 36
JessicaM Avatar answered Oct 30 '22 07:10

JessicaM


You could create your own Button class and use that in the XML layout files...

package com.mycompany.myApp

public class MyButton extends Button {

    public MyButton (Context context, AttributeSet attrs) {
        this.setSoundEffectsEnabled(false);
    }
}

Then in the XML layout files use...

<com.mycompany.myApp.MyButton
    ...
</com.mycompany.myApp.MyButton>

...for your Buttons.

like image 10
Squonk Avatar answered Oct 30 '22 06:10

Squonk


You could create a custom view that extends from Button. Then just set the Sound Effect Enabled to false on its creation.

http://developer.android.com/guide/topics/ui/custom-components.html

You can also go further and make the view know which new custom sound should be played.

like image 1
ddcruver Avatar answered Oct 30 '22 07:10

ddcruver