Getting Started with Vibration
Grant Vibration Permission
before you start implement code, you have to add permission in android manifest :
Import Vibration Library
Get instance of Vibrator from Context
Check device has vibrator
If you want stop vibrate please call :
Vibrate for one time
using the vibrate(long milliseconds)
using the vibrate(long pattern, int repeat)
You can create vibration patterns by passing in an array of longs, each of which represents a duration in milliseconds. The first number is start time delay. Each array entry then alternates between vibrate, sleep, vibrate, sleep, etc.
The following example demonstrates this pattern:
- vibrate 100 milliseconds and sleep 1000 milliseconds
- vibrate 200 milliseconds and sleep 2000 milliseconds
To cause the pattern to repeat, pass in the index into the pattern array at which to start the repeat, or
-1 to disable repeating.