android - 检查小米是否应该振动来电
问题描述
问题是小米特有的。我知道对于普通 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);
}
有人知道如何在小米设备上查看“振动”类别的“通话时也振动”和“静音模式下振动”标志吗?
解决方案
在小米设备上,振动有两种设置: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);
推荐阅读
- android - AsyncTask 没有及时返回值
- google-cloud-platform - 通过 API 生成和更改 Gcloud API-Key
- php - 在foreach中将三个数组合并为一个
- javascript - 为什么我的 User.props 总是未定义?React-Native 和 Redux
- python-3.x - 横向滚动背景
- excel - Excel 动态条件格式
- mysql - 将数据从多个 CSV 加载到 MySQL
- php - 在单个重复值上组合多维数组并添加其他值
- c# - 在 3 层架构中将动态 gridview 文本框值和选择值保存到数据库
- python-3.x - 单击使用python selenium有时出现在屏幕上的按钮