Android 如何从AlarmReceiver打开屏幕?

Android 如何从AlarmReceiver打开屏幕?,android,Android,我有一个应用程序需要在早上运行,它会唤醒屏幕,在晚上它会让屏幕变为空白。我有一个AlarmReceiver扩展了BroadcastReceiver,它正确地接收到了警报。但是,在AlarmReceiver中,我无法更改layoutparams,因为我无法调用getWindow() 所以我的问题是,如何从AlarmReceiver中唤醒屏幕?我还尝试过在MainActivity中使用受保护的void onActivityResult以到达窗口,这可以更改参数,但当设备处于睡眠状态时,警报无法运行i

我有一个应用程序需要在早上运行,它会唤醒屏幕,在晚上它会让屏幕变为空白。我有一个AlarmReceiver扩展了BroadcastReceiver,它正确地接收到了警报。但是,在AlarmReceiver中,我无法更改layoutparams,因为我无法调用getWindow()

所以我的问题是,如何从AlarmReceiver中唤醒屏幕?我还尝试过在MainActivity中使用受保护的void onActivityResult以到达窗口,这可以更改参数,但当设备处于睡眠状态时,警报无法运行intent


谢谢

只需从接收器启动一个新的活动,即可在oncreate()中唤醒屏幕

在接收器中:

@Override
public void onReceive(Context context, Intent intent) {
    Intent myIntent = new Intent(context, MainActivity.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(myIntent);
}
在活动中:

WakeLock screenLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");

screenLock.acquire();

//later
screenLock.release();
清单需要包含:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />