我正在开发一个android游戏,在游戏中我使用以下代码进行振动
public void gameover() {
prefs = activity.getSharedPreferences("AUTHENTICATION_FILE_NAME", Context.MODE_WORLD_WRITEABLE);
String vibration = prefs.getString("vibration", null);
if(vibration != null) {
if(vibration.equals("on")) {
Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
}
}
}但是它在不断地振动。我想在100毫秒后停止这种振动,但它没有停止。我该怎么办?
发布于 2014-04-26 12:57:53
试试这个..。它会帮助你..
Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
v.cancel();发布于 2014-04-26 13:00:53
首先制作可控震源的对象
Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);然后在按钮的onclick事件上声明这段代码。
long[] pattern = {0, 1000, 0};
vb.vibrate(pattern, 0);用于消除振动,然后使用
vb.cancel();https://stackoverflow.com/questions/23306787
复制相似问题