所以几个月前我做了一个应用程序来帮助我改善睡眠。我有睡眠问题,这听起来很奇怪,但我在睡觉时使用该应用程序振动我的手机,让自己专注于睡觉,这是目前我睡眠习惯的一个重要方面。
但是,我昨天将手机更新到了 Android 10,它完全破坏了该应用程序。以前,当我单击开始按钮时应用程序会振动,即使我使用后台服务、广播接收器和唤醒锁锁定手机后,该应用程序也会继续振动。但是现在,应用程序在我锁定手机后停止振动,控制台中没有任何内容说明为什么这样做。
如果有人可以就我可以在代码中更改的内容或其他内容提出建议,我将不胜感激,因为我完全不知道该做什么,我必须以某种方式让它工作。
这是代码:
MainActivity 中处理服务 Vibrate 开始的函数:
// Event for when the VIBRATE button is pressed
public void beginVibration(View view) {
// Given either of the bars are not 0
if (durationBar.getProgress() != 0 || delayBar.getProgress() != 0) {
// Get the values for each bar and set them accordingly in the vibration value array
long[] pattern = {0, durationBar.getProgress(), delayBar.getProgress()};
// Setup the ServiceConnection to monitor the Vibrate service
c = new ServiceConnection() {
@Override
public …Run Code Online (Sandbox Code Playgroud)