启用/禁用键盘声音和振动编程 [英] enable/disable keyboard sound and vibration programmatically

查看:357
本文介绍了启用/禁用键盘声音和振动编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来禁用和敲击按键时启用键盘声音和振动。我搜索上的堆栈溢出的Andr​​oid论坛,但我并没有发现任何结果。

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.

我试过 AudioManager ,使振动模式,但我想激活振动模式和健全的键盘上。

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);

有什么办法如何修改 android.provider.Settings 键盘声音和振动?

推荐答案

根据您的意见:

我说的是android系统中默认的键盘,我想有禁用/启用键盘的声音和振动,当用户敲击键盘的按键,(如在键盘设置)的能力。

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 )

&安培;

我现在在三星Galaxy S2,HTC ONE .​​..等

i'm talking about soft keyboard, like in SAMSUNG GALAXY S2 , HTC ONE ...etc

据我所知,你不能做到这一点,因为每个输入法的内部保持它的声音/振动preference值。例如,见<一href=\"https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/master/java/res/xml/$p$pfs.xml\"相对=nofollow>的Andr​​oid(AOSP)IME (在写本线30〜39):

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" />

正如你可以看到它存储在它的共享preference的震动/声音值。
这适用于市场上大多数的IME。因此,你无法控制所有的IME的从单点震动/声音效果。

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.

这篇关于启用/禁用键盘声音和振动编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆