Android Phone Shake

Source: Internet
Author: User

android for mobile phone shake1. Add vibrate permissions in Androidmanifest.xml<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Uni.vibrator"
Android:versioncode= "1"
Android:versionname= "1.0" >
&LT;USES-SDK android:minsdkversion= "8"/>

<application android:icon= "@drawable/icon" android:label= "@string/app_name" >
<activity android:name= ". Vibratordemoactivity "
Android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

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


2. Achieve Vibration
Package uni.vibrator;

Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.os.Vibrator;

public class Vibratordemoactivity extends Activity {
Private vibrator Vibrator;
/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

/*
* To set the vibration size can be set by changing the pattern, if the opening time is too short, the vibration effect may not feel
* */
Vibrator = (Vibrator) getsystemservice (Context.vibrator_service);
Long [] pattern = {100,400,100,400}; Stop Open Stop Open
Vibrator.vibrate (pattern,2); Repeat two times the above pattern if you want to shake only once, index is set to 1        /*such as: only want to shake once, time is 200ms, can write as        long [] pattern = {0,200};   //Stop opening
        vibrator.vibrate (pattern,-1);           //Repeat two times the above pattern if you want to shake only once, index set-1 */
}

public void OnStop () {
Super.onstop ();
Vibrator.cancel (); Stop shaking
}
}

Android Phone Shake

Related Article

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.