警报管理器不在睡眠模式下广播

时间:2016-04-05 09:43:50

标签: android alarm android-wake-lock

我有Android设备,它始终连接到电源,设备也是根。 我使用命令“input keyevent 26”将我的设备置于睡眠模式,并安排getBroadcast()的未决意图的确切警报,重新启动设备。

但是睡眠模式不会触发警报。

请建议如何在睡眠模式下点火。

以下是一段代码

Intent myIntent = new Intent(PlayerActivity.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(PlayerActivity.this, 0, myIntent, 0);
DateTime dateTime = new DateTime(System.currentTimeMillis() + (delays * 1000));
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, dateTime.getHourOfDay());
calendar.set(Calendar.MINUTE, dateTime.getMinuteOfHour());
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

AlarmReceiver.java

public class AlarmReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        L.v("AlarmReceiver called.");
        final PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "ImsWakeLock");
        wakeLock.acquire();
        wakeLock.release();
        try {
            final Process process = Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot"});
            process.waitFor();
        } catch (Exception e) {
            L.w("Could not reboot", e);
        }
    }
}

请帮忙!

0 个答案:

没有答案