我制作了一个正在监听 PHONE_STATE 变化的 BroadcastReceiver。在 onReceive 方法中,我想关闭系统振动器。我尝试了不同的方法,但到目前为止都没有奏效。
AudioManager audioManager = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
systemVibration = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
或者
Vibrator vib = (Vibrator)ctx.getSystemService(Context.VIBRATOR_SERVICE);
vib.cancel();
或者
System.putInt(ctx.getContentResolver(), System.VIBRATE_ON, 0);
或全部一起。
AudioManager 的第一种方法确实改变了振动的系统设置,但它不影响当前正在进行的设置。
有任何想法吗?
西蒙