在Android 2.2振动设置 [英] Vibrate settings on Android 2.2

查看:198
本文介绍了在Android 2.2振动设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个振动切换小部件(事实上,它的第一个版本已经在市场),但我有一些问题与Android 2.2的震动设置。

I'm making a vibrate toggling widget (in fact, its first version is already in the Market) but I'm having some problems with the vibrate settings of Android 2.2.

截至到Android 2.1我有没有问题,当我想禁用震动我

Up to Android 2.1 I have no problem, when I want to disable vibrate I do

am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF);
am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,AudioManager.VIBRATE_SETTING_OFF);

和相同,但与 VIBRATE_SETTING_ON 在两条线上打开它,和它的作品还好吧。

and the same but with VIBRATE_SETTING_ON on both lines to turn it on, and it works allright.

不过,由于Android 2.2推出的仅在静音模式时振动和振动时,不静音模式,我不知道如何使它发挥作用。当振动被设置为总是或者从不没有任何问题,但只要用户手动将它设置为其他两个设置中的一个,应用程序开始做奇怪的事情。

However, since Android 2.2 introduced "Vibrate only in silent mode" and "Vibrate when not in silent mode", I don't know how to make it work. When vibrate is set to "Always" or "Never" there's no problem, but as soon as the user manually sets it to one of the other two settings, the app starts doing strange things.

例如,如果我有它设置为震动只有在静音模式,我通过我的窗口小部件关闭振动关闭,它将关闭,但是当我重新打开它...它可以追溯到只有在沉默模式,而不是总是。事实上,有没有办法回去将其设置为始终,除非你通过设置这样做 - >声音,所以我猜的组合框振动模式在做别的事情,我不知道。它喜欢它存储的值在别的地方,因为即使我手动设置为常,当我禁用它,并通过小部件(与code我帐前)重新启用它使回到仅振动在静音模式。

For example, if I have it set to "vibrate only in silent mode" and I turn vibration off via my widget, it turns off, but when I turn it back on... it goes back to "only in silent mode" instead of "Always". In fact, there's no way to set it back to "Always" unless you do it via Settings -> Sound, so I guess the combobox for vibrate mode is doing something else that I don't know of. It's like it stored the value somewhere else, because even if I set manually to "Always", when I disable it and enable it again via the widget (with the code I posted before) it keeps going back to "Vibrate only in silent mode".

更糟糕的是,有一个在AudioManager类值仅在静音模式(VIBRATE_SETTING_ONLY_SILENT),但是当你将它设置为只有当不静音模式,它使用VIBRATE_SETTING_ON,所以没有办法检测到它(不,我知道,我的意思)。

And what's more, there's a value in AudioManager class for "Only in silent mode" (VIBRATE_SETTING_ONLY_SILENT) but when you set it to "Only when not in silent mode" it uses VIBRATE_SETTING_ON, so there are no way to detect it (not that I know of, I mean).

希望我一直没太混乱,但我想给所有可能的数据。拥有了这些集...

Hope I have not been too confusing, but I wanted to give all the possible data. And with all that set...

有谁知道如何正确地在2.2处理震动设置?有,我要设置或我必须为禁用或完全使振动调用任何其他变量功能?还是有办法来重置手机到已知状态,这样它的作品好不好?

Does anyone know how to properly handle vibrate settings in 2.2? Is there any other variable that I have to set or function that I have to call in order to disable or enable vibrate completely? Or a way to "reset" the phone to a known state so that it works ok?

再现问题的步骤(或至少其中一个问题)是:

The steps to reproduce the problem (or, at least, one of the problems) are:

  • 设置为震动仅在静音模式,通过设置菜单。

  • Set vibrate to "only in silent mode" via the settings menu.

设置振动为从不通过小工具:

Set vibrate to "never" via the widget:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF);

检查在设置菜单中的振动被设置为从不。

Check in the settings menu that vibrate is set to "never".

设置震动永远通过小工具:

Set vibrate to "always" via the widget:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_ON);

推荐答案

好吧,我想我终于固定它...我看着com.android.settings.Settings类的源$ C ​​$ c和复制部分的,使和方法禁用振动:

Ok, I think I finally fixed it... I looked at the source code of the com.android.settings.Settings class and copied part of the methods that enable and disable vibrate:

<一个href="http://android.git.kernel.org/?p=platform/packages/apps/Settings.git;a=blob;f=src/com/android/settings/SoundSettings.java;h=a735268b119dda3f91b4f3e987df054eead99f5c;hb=HEAD" rel="nofollow">http://android.git.kernel.org/?p=platform/packages/apps/Settings.git;a=blob;f=src/com/android/settings/SoundSettings.java;h=a735268b119dda3f91b4f3e987df054eead99f5c;hb=HEAD

感谢你啦magaio,你指出正确的方向我。)

Thank you anyway magaio, you pointed me in the right direction ;)

这篇关于在Android 2.2振动设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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