标签:
※下面的例子,在程序起动后等待3秒后,振动1秒,再等待2秒后,振动5秒,再等待3秒后,振动1秒
long[] pattern = {3000, 1000, 2000, 5000, 3000, 1000}; //
OFF/ON/OFF/ON…
需要在AndroidManifest.xml里进行下类设定
<uses-permission
android:name=”android.permission.VIBRATE”/>
例程源码(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);
标签:
原文地址:http://www.cnblogs.com/wenfei123chai/p/4256467.html