Cannot resolve symbol USAGE_NOTIFICATION_RINGTONE

617 views Asked by At

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?

2

There are 2 answers

0
Vivek Khare On

try this:

Vibrator androidVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = { 0, 1000, 2000 };
androidVibrator.vibrate(pattern, 0);
4
Floern On

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.