2012-05-04 58 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