Android上的振动器

时间:2012-05-04 06:19:29

标签: java android

我在Stackoverflow上阅读了很多关于这个问题的内容,但是没有帮助她解决我的问题。

在我的源代码中,我有这个。

vibretor  = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
vibretor.vibrate(600);

在AndroidManifeste.xml中我有权限

<uses-permission android:name="android.permission.VIBRATE"/>

我认为这是可以的,因为我查了一下 http://developer.android.com

但它根本没有任何问题:( 所以,让你有人了解我如何才能让它发挥作用?

我的测试设备有:Eee Pad Transformer,三星Galaxy S2和三星Galaxy Tab 10.1

2 个答案:

答案 0 :(得分:5)

问题解决了。

问题是,在android 4.0下,振动设置必须是

触摸振动

而不是

铃声 要么 通知

然后它可以使用我的代码。

vibretor  = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
vibretor.vibrate(600);

答案 1 :(得分:1)

public void vibrate(int duration)
              {
   Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
   v.vibrate(duration);    
              }
vibrate(10000);
相关问题