摇一摇控制手机震动

来源:互联网 发布:python 中文编码转换 编辑:程序博客网 时间:2024/06/02 15:02
sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);v = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);


获得传感器管理器和震动器。

mSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);sm.registerListener(this, mSensor,SensorManager.SENSOR_DELAY_GAME);

设置传感器默认精度,注册传感器为游戏模式。

v.vibrate(400);


使振动器震动固定时间。

sm.unregisterListener(this);

取消传感器管理器注册。

源码下载:

http://download.csdn.net/download/gb_young/5313753

原创粉丝点击