-3

I am able to make my android device vibrate using v.vibrate(pattern, -1); However, the android page describes another link to insert an AudioAttribute. However, the following line gives me an error.

    cannot resolve symbol USAGE_NOTIFICATION_RINGTONE: 
    v.vibrate(pattern, -1, USAGE_NOTIFICATION_RINGTONE); 

What should I do?

Binnut
  • 90
  • 7
Sunil Nair
  • 383
  • 2
  • 5
  • 15

2 Answers2

0

try this:

Vibrator androidVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = { 0, 1000, 2000 };
androidVibrator.vibrate(pattern, 0);
beresfordt
  • 5,088
  • 10
  • 35
  • 43
Vivek Khare
  • 162
  • 4
0

The constant USAGE_NOTIFICATION_RINGTONE is a property of AudioAttribute which means you have to reference it properly:

v.vibrate(pattern, -1, new AudioAttributes.Builder()
         .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());

and don't forget to include android.media.AudioAttributes.

Floern
  • 33,559
  • 24
  • 104
  • 119
  • v.vibrate(pattern, -1, AudioAttributes.USAGE_NOTIFICATION_RINGTONE); The error says that it expects an integer argument. – Sunil Nair Jun 25 '15 at 09:52
  • I updated my answer. Also keep in mind, that this is only available in Android 5.0 and newer. – Floern Jun 25 '15 at 09:58
  • Thanks. My code builds without error. however, I cannot yet understand the difference in the meaning of these two lines of code: a) v.vibrate(pattern, -1); b) v.vibrate(pattern, -1, new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build()); – Sunil Nair Jun 25 '15 at 10:08
  • With the `AudioAttributes` you can specify some sort of 'context'. If you don't need that I suggest to use `v.vibrate(pattern, -1);`. – Floern Jun 25 '15 at 10:57