Android 检查小米是否应该为通话振动

Android 检查小米是否应该为通话振动,android,call,android-vibration,Android,Call,Android Vibration,这个问题是针对小米的。我知道,对于普通安卓操作系统上的设备,也存在类似的问题 有不同的方法可以理解Android手机是否处于100%纯振动模式,或者其“通话时振动”是否处于正常模式 小米的问题是。。。没有人工作。至少,从清单中我有: /** * This method should tell us if the vibration is on in the Android System settings */ public boolean checkVibrationIsOn

这个问题是针对小米的。我知道,对于普通安卓操作系统上的设备,也存在类似的问题

有不同的方法可以理解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);
  }

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

小米设备上有两种振动设置:正常振动和静音振动。 您需要分析RingerMode和调用设置。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外壳设置列表系统”时,结果中并没有包含这些设置。在我第一次更改后,设置已存在。请检查更改后是否显示设置?您可以为其运行“adb外壳设置列表系统”命令。确定,再次测试。结果:如果这些参数不在Setting.System中,则这两个参数的默认值均为“enabled”。电话应用程序将这些参数保存到Settings.System中。“呼叫时振动”更改“正常时振动”和“响铃时振动”。但小米用的是“正常振动”。有意思。:-)@user1081783非常感谢。嗯,但无法更改:java.lang.IllegalArgumentException:您不能将设置保留在安全设置中。也许只有根设备。