问题
Ok so I'm very new to android. My gf asked me to make a very simple app for her so she could easily switch from always vibrate to never vibrate. Seemed like a simple enough task. So I've got a toggle button, and it changes the setting, but I keep running into one big issue. It won't change between always and never. if I set it to always it will swap between always and only in silent mode, or if I set it to never it switches between only not in silent mode and never. did I miss some obvious but mudane detail? this is my swap code.
public void onClick(View arg0) {
if (vibrateOn) {
vibrateOn = false;
adManag.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
adManag.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
} else {
vibrateOn = true;
adManag.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
adManag.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
}
Log.d(TAG, "after " + Integer.toString(adManag.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)));
}
来源:https://stackoverflow.com/questions/11264550/changing-vibrate-setting