In Android, follow these steps:
A. Obtain the mobile phone vibration service through the system service. Vibrator vibrator = (Vibrator) getSystemService (VIBRATOR_SERVICE );
B. Check whether the vibrator exists after obtaining the vibration service:
Vibrator. hasVibrator ();
Checks whether the current hardware has a vibrator. If yes, true is returned. If no, false is returned.
C. Make appropriate calls based on actual needs,
Vibrator. vibrate (long milliseconds );
Start vibrator for milliseconds in milliseconds.
Vibrator. vibrate (long [] pattern, int repeat );
Start vibrator again in pattern mode. (Pattern is in the form of new long [] {arg1, arg2, arg3, arg4 ......}, take two groups, such as arg1 and arg2, as a group, and arg3 and arg4 as a group. The first one in each group represents how many seconds to wait to start vibrator, the last one indicates how many milliseconds the vibrator has stopped, and then it can be reciprocating. Repeat indicates the number of repetitions. If it is-1, it indicates that the operation is not repeated only once in the pattern format ).
Vibrator. cancel ();
Vibrator stops.
Note: The following permissions are required when using the vibration service: android. permission. VIBRATE
From tianshijianbing1989