【发布时间】:2014-01-02 20:11:02
【问题描述】:
我创建了一个正在监听 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 的第一种方法确实改变了振动的系统设置,但不会影响当前正在进行的设置。
有什么想法吗?
西蒙
【问题讨论】:
标签: android broadcastreceiver vibration