Android Vibration while locked/sleep

我与影子孤独终老i 提交于 2020-01-17 05:34:09

问题


Whether the user has the screen on or off I want to notify the user by a vibration. If the screen is on, this works well:

Vibrator vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                            long sleep = 100;
                            long vibrate = 500;
                            long[] vibratePattern = {0, vibrate, sleep, vibrate, sleep};
                            vibrator.vibrate(vibratePattern, -1); 

Its called by a Thread that is implemented in a Service.

The Thread runs always even if the screen is off. I checked that because im implementing a timer. So that cant be the problem!


回答1:


Not sure if you have looked into Android's Notifications, but sounds like this would be perfect for what you are trying to achieve.

http://developer.android.com/intl/es/reference/android/app/Notification.Builder.html

when building a notification, you can cause your phone to vibrate with the setVibrate() method.



来源:https://stackoverflow.com/questions/36755195/android-vibration-while-locked-sleep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!