Bhaskar
Bhaskar

Reputation: 949

how to disable vibrator in android phone programatically

I'm trying to disable the vibrator using vibrator.cancel() but it is not working. How should I disable it? I have tried following code:

Vibrator vib = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
vib.cancel()

Upvotes: 0

Views: 205

Answers (2)

Aditya Vyas-Lakhan
Aditya Vyas-Lakhan

Reputation: 13555

Try this way,,it will help

switch (position) {
    case 0:
        audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        break;
    case 1:
        audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
        break;
    case 2:
        audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, 
                AudioManager.VIBRATE_SETTING_OFF);
        break;
    case 3:
        audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, 
                AudioManager.VIBRATE_SETTING_ON);
        break;
    }

Upvotes: 1

Amit Basliyal
Amit Basliyal

Reputation: 870

We can enable and disable vibrator like this

AudioManager vib = (AudioManager) this.getSystemService(Context.VIBRATOR_SERVICE);

Enable silent mode

vib.setRingerMode(AudioManager.RINGER_MODE_SILENT);

Disable silent mode

vib..setRingerMode(AudioManager.RINGER_MODE_NORMAL);

it may be help you or someone else

Upvotes: 2

Related Questions