Tags:androidvibrator Vibrator It |
Category: Andorid |
Get the Vibrator Vibrator instance: Vibrator Mvibrator = (vibrator) context.getsystemservice (Context.vibrator_service); Vibrator.vibrate () Method: When there are only 1 parameters, the first parameter is used to specify the number of milliseconds to vibrate. To pass 2 parameters, the 1th parameter specifies a sample of the vibration time, and the 2nd parameter is used to specify whether a loop is required. A sample of the vibrational time is the interaction of the vibrating time and the wait time with the specified array.
※ The following example, after the program started to wait 3 seconds, vibration 1 seconds, and then wait 2 seconds, vibration 5 seconds, and then wait 3 seconds, vibration 1 seconds
Long[] Pattern = {3000, 1000, 2000, 5000, 3000, 1000}; Off/on/off/on ...
The following class settings are required in the androidmanifest.xml.
<uses-permission android:name= "Android.permission.VIBRATE"/>
Example Routines Code (JAVA)
public class Vibratortestactivity extends Activity {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Vibrator Vibrator = (Vibrator) getsystemservice (Vibrator_service);
Long[] Pattern = {3000, 1000, 2000, 5000, 3000, 1000}; Off/on/off/on
Vibrator.vibrate (Pattern,-1);
}
@Override
public boolean ontouchevent (Motionevent event) {
if (event.getaction () = = Motionevent.action_move) {
Vibrator Vibrator = (Vibrator) getsystemservice (Vibrator_service);
Vibrator.vibrate (10);
}
Return Super.ontouchevent (event);
Andorid Mobile Phone Vibrator (vibrator) use