2016-03-14 43 views
0

我正在做一個基本的通知應用程序,只是想集成一個天文鐘。 我已準備好基本通知。Android天文臺:setUsesChronometer

如何添加天文臺使用:setUsesChronometer();

而且我該如何使用setVibrate()方法呢?

回答

1

無論您在何處創建通知,都可以在下面的行中添加Chronometer數據到您的通知中。

 long elapsedTime = SystemClock.elapsedRealtime() - mChronometer.getBase(); 
     notification.setWhen(System.currentTimeMillis()- elapsedTime); 

     notification.setUsesChronometer(true); 

對於振動,需要定義振動模式 -

.setVibrate(new long[]{500,1000}) //vibrates at 5000 ms and 1 second. 
+0

mChronometer.getBase(); 我給我一個錯誤說 非靜態connot被靜態上下文引用 – Alex

+0

請粘貼相關的代碼。 –