Getting Started with Vibration

suggest change

Grant Vibration Permission

Before you implement the vibration code, add this permission to the Android manifest:

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

Import Vibration Library

import android.os.Vibrator;

Get instance of Vibrator from Context

Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

Check that the device has a vibrator

vibrator is the instance from the previous step.

boolean isHaveVibrate() {
    return vibrator != null && vibrator.hasVibrator();
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents