4

In my application, I want turn off the vibration when notification comes. I am able to mute the sound of notification but not able to stop the vibration.

To mute the sound of notification, I have used following code:

 if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != value) {
        audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, value, 0);
        Utils.log("Volume Changed to " + value);
    }

Please suggest how to change the notification vibration intensity to zero or suggest some other way to cancel vibration when notification arrives.

audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
        AudioManager.VIBRATE_SETTING_OFF);

setVibrateSetting is not working and is deprecated

I can manually change vibration intensity of notification in Samsung devices by:

  1. Go to Setting
  2. Go to My Device tab
  3. Tap on Sound and open “Vibration intensity”
  4. Choose the vibration intensity for Incoming Call, Notification, and Haptic Feedback

But how can I do it programatically? please help.

SiHa
  • 7,830
  • 13
  • 34
  • 43
shivani gupta
  • 235
  • 4
  • 20
  • By default I guess should not vibrate. Are you using NotificationCompat? A quick solution could be to remove the android.permission.VIBRATE from your manifest. – Alex Nov 19 '16 at 08:26
  • No i am not using NotificationCompat. By default vibration is on – shivani gupta Nov 19 '16 at 08:38
  • There is no "Vibration intensity" option in standard Android. What you are seeing was added by your device manufacturer for your device. – CommonsWare Nov 25 '16 at 20:38
  • this question is similar to http://stackoverflow.com/questions/11483168/android-set-power-of-vibration – Ashrith K S Nov 29 '16 at 14:01
  • how about [this](https://developer.android.com/reference/android/os/Vibrator.html#cancel()), give it a try – Nishant Verma Nov 30 '16 at 02:29

2 Answers2

4

Usually in cell phones and similar devices vibration implements by small dis-balanced motor which causes the vibration when its powered on. This motor usually has no control except on/off, so You can control vibration duration, not it's level.

In this case You can use Pulse-width modulation (PWM) approach (like on fig.) to control vibration intensity: set some period T (for example 1 sec) and first time 900 ms of it (tv1) set vibrate to on and 100 ms (ts1) - keep vibrate off. Than 800 ms (tv2) of it set vibrate to on and 200 ms (ts2) - keep vibrate off, etc. until time of vibrate on become 0.

PWM vibration control

On Android vibrator control implemented in Vibrator class.

As @Rohit J proposed, You can use vibrate pattern (described here) for that, like:

long[] pattern = {
        0,     // start vibrate immediately
        900,   // vibrate 1 900 ms
        100,   // silence 1 100 ms
        800,   // vibrate 2 800 ms
        200,   // silence 2 200 ms
        700,
        300,
        600,
        400,
        500,
        500,
        400,
        600,
        300,
        700,
        200,
        800,
        100,
        900,
};

and add it to Notification:

Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent)
        ...
        .setVibrate(pattern)
        ...;

NB! Also You can create (manual or programmatically) more complex pattern for vibration control for more smoothed intensity change (for example not create long solid pulse of vibration but many short and decrease not duration of vibration, but quantity of that pulses, something like Pulse-density modulation).

Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
3

The only solution to this problem is to keep the silent mode on. In the latest versions of Android we cannot turn off the default vibration.

jkmartindale
  • 523
  • 2
  • 9
  • 22
shivani gupta
  • 235
  • 4
  • 20