我创建了一个 BroadcastReceiver 从 AlarmManager 打开屏幕。这是我的代码OnReceive
。
@Override
public void onReceive(Context arg0, Intent arg1) {
Log.i("", "OnReceive");
// Initializes the PowerManager.
PowerManager powerManager = (PowerManager) arg0
.getSystemService(Context.POWER_SERVICE);
// Wakes device.
WakeLock wakeLock = powerManager.newWakeLock(
PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "Stretching");
wakeLock.acquire();
wakeLock.release();
wakeLock = null;
// Calls activity.
Intent intent = new Intent(arg0, TrainingActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(intent);
}
出现问题是因为FULL_WAKE_LOCK
已弃用,所以我尝试使用PARTIAL_WAKE_LOCK
,但随后屏幕无法打开。我应该改用什么?我搜索了这个如何在部分唤醒锁定期间打开屏幕,但它也在使用FULL_WAKE_LOCK
.