How to vibrate wearable

Thanks to stackoverflow.

Add this to manifest.

<uses-permission android:name="android.permission.VIBRATE"/>

Then in code

Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        long[] vibrationPattern = {0, 500, 50, 300};
        //-1 - don't repeat
        final int indexInPatternToRepeat = -1;
        vibrator.vibrate(vibrationPattern, indexInPatternToRepeat);

If you don’t need a pattern then you can simply specify a duration in milliseconds.

Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        vibrator.vibrate(100);

 

This entry was posted in Android, Wearable. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *