Changing vibrate setting

2019-08-09 09:06发布

问题:

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)));
        }