package com.android.vibrator;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.app.Activity;
public class MainActivity extends Activity {
private Vibrator vibrator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);//从系统中获取震动对象
}
public void click1(View view){
vibrator.vibrate(5000);//震动五秒
}
public void click2(View view){
vibrator.cancel();//取消震动
}
public void click3(View view){
long[] a={100,1000,100,2000,100,3000};//隔0.1秒震动一分钟,再隔0.1秒震动两分钟,再隔一秒震动三分钟
vibrator.vibrate(a, 0);//第二个参数为从数组哪里开始重复震动,为-1时表示不重复,0表示从下表为0的地方开始重复震动
}
}