RTC_WAKEUP is not working

蹲街弑〆低调 提交于 2019-12-03 03:54:47

RTC_WAKEUP will not switch on the screen, all it does is wakes up thee cpu so that your job is done. For the Screen to be turned on you need a FULL wakelock to be acquired.

PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
                                      | PowerManager.ON_AFTER_RELEASE,
                                      "wakeup");
 wl.acquire();
 // ... do work...
//show toask
 wl.release();

Do yo have the permission in your Manifest?

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

Fix your manifest. Instead of

<receiver android:name="MyBroadcastReceiver" >

you need:

<receiver android:name=".MyBroadcastReceiver" >

Checked the google DeskClock app: com.android.deskclock.alarms.AlarmStateManager (it's a BroadcastReceiver)

In its onReceive function used goAsync():

@Override
public void onReceive(final Context context, final Intent intent) {
    final PendingResult result = goAsync();
    final PowerManager.WakeLock wl = AlarmAlertWakeLock.createPartialWakeLock(context);
    wl.acquire();
    AsyncHandler.post(new Runnable() {
        @Override
        public void run() {
            handleIntent(context, intent);
            result.finish();
            wl.release();
        }
    });
}

You should take a shot with that.

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