在使用振动插件 (org.apache.cordova.vibration 0.3.11) 时,我搜索了一种解决方案,使我的 Android Phonegap 应用程序尊重静音音频设置
https://github.com/apache/cordova-plugin-vibration
但似乎没有办法避免Android设备静音状态下的振动。或者现在有人设置吗?
所以我应用了以下补丁,这似乎对我有用。
编辑 Vibration.java 文件并在触发振动之前检查 AudioManager.RINGER_MODE_SILENT:
import android.media.AudioManager; // new
public void vibrate(long time) {
// Start the vibration, 0 defaults to half a second.
if (time == 0) {
time = 500;
}
// OLD Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
// OLD vibrator.vibrate(time);
AudioManager manager = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
// respect silent rintone mode
if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(time);
}
}
public void vibrateWithPattern(long[] pattern, int repeat) {
// OLD Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
// OLD vibrator.vibrate(pattern, repeat);
AudioManager manager = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
// respect silent rintone mode
if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(pattern, repeat);
}
}
有谁知道没有任何补丁的更智能的解决方案?