首页 > 解决方案 > 检查小米是否应该振动来电

问题描述

问题是小米特有的。我知道对于普通 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);
  }

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

标签: androidcallandroid-vibration

解决方案


在小米设备上,振动有两种设置: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);

推荐阅读