【问题标题】:Check if a Xiaomi should vibrate for calls检查小米是否应该振动来电
【发布时间】:2019-01-15 13:37:15
【问题描述】:

这个问题是针对小米的。我知道在普通 Android 操作系统上的设备也有类似的问题。

有多种方法可以了解 Android 手机是处于 100% 仅振动模式,还是在正常模式下打开了“通话时振动”。

小米的问题是……没有人工作。至少,从我的列表中:

  /**
   * This method should tell us if the vibration is on in the Android System settings
   */
  public boolean checkVibrationIsOn() {
    boolean status = false;
    if (isInVibrationMode()
        || isVibrationOnHacky()
        || isVibrationOnDeprecated()) {
      status = true;
    }
    return status;
  }

  /**
   * Check if the phone is in Vibration mode
   */
  private boolean isInVibrationMode() {
    return audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE;
  }

  /**
   * Use a direct access to get status of Vibration. Works not on all kinds of phones
   */
  private boolean isVibrationOnHacky() {
    return 0 != Settings.System.getInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING,0);
  }

  /**
   * Use a deprecated method to get status of Vibration. It was deprecated so usual apps can't use it
   * but it works on some devices
   */
  private boolean isVibrationOnDeprecated() {
    return audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL
        && audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER);
  }

有人知道如何在小米设备上查看“振动”类别的“通话时也振动”和“静音模式下振动”标志吗?

【问题讨论】:

    标签: android call android-vibration


    【解决方案1】:

    在小米设备上有两种振动设置:vibrate_in_normal 和 vibrate_in_silent。 您将需要分析 RingerMode 并使用适当的常量调用 Settings.System.getInt():

    if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL)
        return Settings.System.getInt(context.getContentResolver(), "vibrate_in_normal",0);
    else
        return Settings.System.getInt(context.getContentResolver(), "vibrate_in_silent",0);
    

    【讨论】:

    • 抱歉,这不起作用。 getInt() 都返回默认值。在 Redmi Note 9 Pro、Android 10、MIUI 11 中测试。
    • 刚刚检查了一个新设备,默认情况下它们是空的。当我运行 cmd "adb shell settings list system" 时,结果中不包含这些设置。在我第一次更改后,设置是存在的,请您检查一下更改设置后是否出现?你可以为它运行“adb shell settings list system”命令。
    • 好的,再次测试。结果:如果这些参数不在 Setting.System 中,则两者的默认值都是“启用”。电话应用程序将这些参数保存到 Settings.System 中。 “通话时振动”同时更改“vibrate_in_normal”和“vibrate_when _ringing”。但小米使用“vibrate_in_normal”。有趣的。 :-) @user1081783 非常感谢。
    • 嗯,但无法更改它:java.lang.IllegalArgumentException:您无法将设置保存在安全设置中。也许只在有根设备中。
    • 看来小米在某些版本中做了改动,修改了VIBRATE_WHEN_RINGING设置,所以不需要对小米设备进行具体处理。问题中的代码应该可以正常工作。
    猜你喜欢
    • 1970-01-01
    • 2021-03-26
    • 2020-03-07
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多