Android 2.2 上的振动设置

发布于 2024-09-24 03:53:32 字数 1462 浏览 7 评论 0原文

我正在制作一个振动切换小部件(事实上,它的第一个版本已经在市场中),但我在 Android 2.2 的振动设置方面遇到了一些问题。

直到 Android 2.1,我都没有问题,当我想禁用振动时,我会这样做

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

,但在两行上都使用 VIBRATE_SETTING_ON 将其打开,并且工作正常。

但是,由于Android 2.2引入了“仅在静音模式下振动”和“非静音模式下振动”,我不知道如何使其工作。当振动设置为“始终”或“从不”时,没有问题,但一旦用户手动将其设置为其他两个设置之一,应用程序就会开始做奇怪的事情。

例如,如果我将其设置为“仅在静音模式下振动”,并且通过小部件关闭振动,它会关闭,但是当我重新打开它时...它会返回到“仅在静音模式下”的“永远”。事实上,除非您通过“设置”->“设置”来将其设置回“始终”,否则无法将其设置回“始终”。声音,所以我猜振动模式的组合框正在做一些我不知道的事情。就像它将该值存储在其他地方一样,因为即使我手动设置为“始终”,当我禁用它并通过小部件再次启用它(使用我之前发布的代码)时,它仍然会返回到“仅在静音模式下振动” ”。

更重要的是,AudioManager 类中有一个值“仅在静音模式下”(VIBRATE_SETTING_ONLY_SILENT),但是当您将其设置为“仅在不处于静音模式时”时,它会使用 VIBRATE_SETTING_ON,因此无法检测到它(不是说我我的意思是知道)。

希望我没有太困惑,但我想提供所有可能的数据。有了所有这些设置...

有人知道如何正确处理 2.2 中的振动设置吗?为了完全禁用或启用振动,我是否必须设置或调用任何其他变量?或者有一种方法可以将手机“重置”到已知状态以使其正常工作?

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

  • 通过设置菜单将振动设置为“仅在静音模式下”。

  • 通过小部件将振动设置为“从不”:

    setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);

  • 检查设置菜单中振动是否设置为“从不”。

  • 通过小部件将振动设置为“始终”:

    setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);

  • 进入设置菜单 ->振动设置为“仅在静音模式下”

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.

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

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

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.

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

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...

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

  • Go to the settings menu -> Vibrate is set to "Only in silent mode"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微暖i 2024-10-01 03:53:32

当某些应用程序搞乱了我的 Nexus One 的个人设置时,我不得不自己修改这些设置。它们是:

始终在响铃上振动:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);

从不在响铃上振动:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);

仅在静音时在响铃上振动:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);

始终在通知时振动:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);

通知时切勿振动:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);

仅在无声状态下通知时振动:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ONLY_SILENT);

更改铃声模式:

AudioManager.setRingerMode(RINGER_MODE_NORMAL);
AudioManager.setRingerMode(RINGER_MODE_SILENT);
AudioManager.setRingerMode(RINGER_MODE_VIBRATE);

振动设置独立于铃声设置。混乱随之而来。

I had to mess with these settings myself when some application messed up my Nexus One's individual settings. Here they are:

Always vibrate on ring:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);

Never vibrate on ring:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);

Vibrate on ring in silent only:

setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);

Always vibrate on notify:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);

Never vibrate on notify:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);

Vibrate on notify in silent only:

setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ONLY_SILENT);

Change ringer mode:

AudioManager.setRingerMode(RINGER_MODE_NORMAL);
AudioManager.setRingerMode(RINGER_MODE_SILENT);
AudioManager.setRingerMode(RINGER_MODE_VIBRATE);

Vibrate settings are independent of ringer settings. Confusion ensues.

孤檠 2024-10-01 03:53:32

好吧,我想我终于修好了。
我查看了 com.android.settings.Settings 类的源代码,并复制了部分启用和禁用振动的方法:
https:// android.googlesource.com/platform/packages/apps/Settings/+/master/src/com/android/settings/SoundSettings.java

无论如何,谢谢你magaio,你为我指明了正确的方向。

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:
https://android.googlesource.com/platform/packages/apps/Settings/+/master/src/com/android/settings/SoundSettings.java

Thank you anyway magaio, you pointed me in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文