enable/disable keyboard sound and vibration programmatically
Solution 1
As per your comments:
i'm talking about the default keyboard in android , i want to have the ability to disable / enable keyboard sound and vibration when user tap a key in keyboard,( like in Settings of Keyboard )
&
i'm talking about soft keyboard, like in SAMSUNG GALAXY S2 , HTC ONE ...etc
AFAIK, you can not accomplish this as each input method keeps its sound/vibration preference values internally. See for example Android (AOSP) IMe (as of this writing lines 30~39):
<CheckBoxPreference
android:key="vibrate_on"
android:title="@string/vibrate_on_keypress"
android:defaultValue="@bool/config_default_vibration_enabled"
android:persistent="true" />
<CheckBoxPreference
android:key="sound_on"
android:title="@string/sound_on_keypress"
android:defaultValue="@bool/config_default_sound_enabled"
android:persistent="true" />
As you can see it stores the vibrate/sound values in its shared preference. That applies to most of IMe in the market. Hence, you can not control vibrate/sound effect for all IMe's from single point.
Solution 2
Have a look at How to disable default sound effects for all my application or activity for disabling tap-sounds.
To disable Haptic feedback and touch sounds programmatically have a look at http://developer.android.com/reference/android/view/View.html#setHapticFeedbackEnabled(boolean) http://developer.android.com/reference/android/view/View.html#setSoundEffectsEnabled(boolean)
Easier done is by defining the following in your styles.xml
<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:soundEffectsEnabled">false</item>
<item name="android:hapticFeedbackEnabled">false</item>
</style>
and in your manifest.xml
<application [...] android:theme="@style/AppTheme" >
Related videos on Youtube
Houcine
I'm a Mobile Software Engineer Android / IOS. feel free to contact me via my blog if you have any suggestions, questions or issues. Follow us on Facebook
Updated on June 04, 2022Comments
-
Houcine almost 2 years
I'm trying to find a way to disable and enable keyboard sound and vibration when tapping keys. I've searched on Stack Overflow and other Android Forums but i didn't found any result.
I've tried
AudioManager
to enable vibrate mode, but i want to activate the vibrate mode and sound on keyboard.audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
Is there any way how to change
android.provider.Settings
for keyboard sound and vibration ?-
Houcineno it doesn't help @Ali , i've already tried that , i want the volume of Ring and Media to be NORMAL ,and only disable or enable keyboard tap sound and vibration.
-
AliWould putting the phone in silent mode help? This largely depends on the type of app you have. But you could just do:
AudioManager audio_mngr = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
thenaudio_mngr .setRingerMode(AudioManager.RINGER_MODE_SILENT);
. -
Houcinei'm talking about the default keyboard in android , i want to have the ability to disable / enable keyboard sound and vibration when user tap a key in keyboard,( like in Settings of Keyboard ) ,
-
-
Houcine almost 11 yearsthis is not for keyboard keys ,
-
Alexander Pacha almost 11 yearsCould you explain "keyboard keys"? Do you mean the soft-keyboard (which is displayed on the screen), or the hard-keyboard (e.g. attachted to an ASUS Transformer-Pad). So you want to turn off the haptic feedback and sounds, when the user uses the keyboard?
-
Houcine almost 11 yearsi'm talking about soft keyboard, like in SAMSUNG GALAXY S2 , HTC ONE ...etc
-
Alexander Pacha almost 11 yearsThen you might need a dirty hack (only available for rooted devices), as described in stackoverflow.com/questions/7392067/….
-
Upendra Shah over 6 yearsCan you explain this? I can't understand where and how to implement this. @ozbek
-
ozbek over 6 years@UpendraShah, are you developing an IME?
-
Upendra Shah over 6 yearsActually I want to handle vibrate_on_keypress and sound_on_keypress from my application, so I want to enable or disable these pragmatically.
-
ozbek over 6 years@UpendraShah: as mentioned in the answer, that is not possible at this moment.
-
Upendra Shah over 6 yearsIs is possible if I get root access to device?? @ozbek
-
ozbek over 6 years@UpendraShah: even with the root access, that's not what you want. You will have disassemble the IME apk(s), locate where they are setting those values, change them to your liking, repacking the IME apk(s), sign the package(s) appropriately, push the apk(s) to the target device.
-
Upendra Shah over 6 yearsI have done these with root access. You can check that in Answer below @ozbek