0

I am making simple application, which is changing volume settings.

I want to implement there toggling vibration when ringing or receiving notification. I was using AudioManager.setVibrateSetting(int vibrateType, int vibrateSetting), but this method is deprecated on API level 16.

Do you know about any other way, how to do that?

cubicap
  • 1
  • 1
  • Possible duplicate of [How to make an Android device vibrate?](http://stackoverflow.com/questions/13950338/how-to-make-an-android-device-vibrate) – Yasir Tahir May 08 '16 at 10:27
  • It is highly recommended that, before posting your question, Try to search SO. This question has already been asked and there are many possible ways in the form of answers provided for you to try. If you find none of them working for you, Then ask your question with the reference of your tried solutions. This is how SO works! – Yasir Tahir May 08 '16 at 10:30

1 Answers1

0
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

// Start without a delay
// Vibrate for 100 milliseconds
// Sleep for 1000 milliseconds
long[] pattern = {0, 100, 1000};

// The '0' here means to repeat indefinitely ('-1' here means to vibrate once, as '-1' is out of bounds in the pattern array)
// '0' is actually the index at which the pattern keeps repeating from (the start)
// To repeat the pattern from any other point, you could increase the index, e.g. '1'
v.vibrate(pattern, 0);

Please Give this a try.

Harsh4789
  • 672
  • 7
  • 17
  • Thanks, but I need to toggle the phone's vibration when ringing, the vibration itself is not toggled by me. I set only if it should vibrate or not. – cubicap May 08 '16 at 10:46
  • Are you using media player for ringing ? Or you need the same for notification ringing alert ? – Harsh4789 May 08 '16 at 10:53
  • I just want to toggle the vibration, when is for example incoming call or I receive notification. – cubicap May 08 '16 at 19:00
  • You cannot modify system notification vibration. In your app, whenever you need to show notification you should use such kind of vibration pattern. For example you can referrer this link. http://stackoverflow.com/questions/18253482/vibrate-and-sound-defaults-on-notification – Harsh4789 May 09 '16 at 09:53
  • So anything like `AudioManager.setVibrateSetting(int vibrateType, int vibrateSetting)` doesn't exist for higher API? – cubicap May 09 '16 at 12:21
  • to best of my knowledge no, can you please share your code here ? that would give better idea. – Harsh4789 May 09 '16 at 13:51
  • Can you please point out which .java file has vibration code ? So I will directly go through it. – Harsh4789 May 12 '16 at 18:24
  • Hi. Tried a lot to find the alternative of this deprecated API but seems nothing. Here is the reference link that also says nothing for this problem is available. http://stackoverflow.com/questions/14087322/enabling-and-disabling-vibration-in-android-programmatically – Harsh4789 May 15 '16 at 05:50
  • That's a shame, but anyway thank you very much for time, you spent on this. – cubicap May 15 '16 at 06:44
  • I will try to look on this as and when manage time, please share your skype id so we can further discuss in detail in case required. – Harsh4789 May 15 '16 at 07:07