Andorid Mobile Phone Vibrator (vibrator) use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.