2012-05-04 115 views
2

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

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

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

,并在AndroidManifeste.xml我有权限

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

这是我想是因为我看它在

,但它不借机都没事: ( 所以有你这样的人一个想法,我怎么能得到它的工作

我的测试设备包括:?Eee Pad的TRANSFO rmer,Samsung Galaxy S2和Samsung Galaxy Tab 10.1

+0

又见http://stackoverflow.com/q/3108154/517561,http://stackoverflow.com/q/4430781/517561 – Sparky

+1

没有ü尝试像5000,而不是600一些较大的值,bcoz 600可能是微小的毫秒。 –

+0

试试这个'Vibrator vib =(Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vib.vibrate(600);' – COD3BOY

回答

5

问题已解决。

的问题是,在安卓4.0,振动设置必须

触摸振动

,而不是

铃声通知

然后它与我的工作码。

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

谢谢!在我的Note3上,它是设备>声音>振动强度>通知 – OlivierM

1
public void vibrate(int duration) 
       { 
    Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); 
    v.vibrate(duration);  
       } 
vibrate(10000); 
+1

为什么你想要将参数作为'String'并将其转换为'int'?你为什么不直接把它当作'int'呢? – COD3BOY

+0

我已经在我的应用程序中使用了这个。因为我已经从文本框中获得振动持续时间,所以我已经作为字符串传递。现在检查编辑后的代码。 – Ponmalar