2012-03-22 91 views
0

我正在开发一个应用程序,该应用程序在打开3000毫秒后开始振动。我有以下两行代码:触摸屏幕后的振动

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 
v.vibrate(3000); 

我想写这将启动用户触摸屏幕后振动的机器人代码。请帮帮我。

+0

该代码应该工作。你设置了权限吗? Emran 2012-03-22 23:02:18

回答

4

在你Activity

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    if (ev.getAction() == MotionEvent.ACTION_UP) { 
     yourVibrateFunction(); 
    } 

    return super.dispatchTouchEvent(ev); 
} 
+0

非常感谢。这正是我想要的! – androidGirl 2012-03-22 23:41:23

+1

很高兴工作。但是,不要在评论中发布“谢谢”,而要将答案标记为已接受。 – 2012-03-23 00:01:22