这对Lollipop无效。
启用振动:
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_ON);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_ON);
禁用振动:
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
AudioManager.VIBRATE_SETTING_OFF);
audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
AudioManager.VIBRATE_SETTING_OFF);
这将在Kitkat中发挥出色。
答案 0 :(得分:0)
You can control the vibration on Lollipop with this code:
Settings.System.putInt(getContentResolver(), "vibrate_when_ringing", vibrate?1:0);
Also you need to add this permission to your manifest file:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
Please note however, that the above code won't allow you to change the vibration while the phone rings. I guess the phone app reads this setting before the ringing starts, and uses it until the ringing stops.