android:闹钟无法唤醒设备

发布于 2025-01-06 13:49:18 字数 1506 浏览 1 评论 0原文

当设备未睡眠时,以下工作正常,但是如果我关闭设备 - 它不会在指定时间唤醒。

我可能错过了什么吗?预先感谢您的帮助。

onReceive

@Override
public void onReceive(Context context, Intent intent) {         
    WakeLocker.acquire(context);  

        pk = Integer.parseInt(intent.getExtras().get("pk").toString());     
        Intent intent2 = new Intent(context,ALERT.class);
        intent2.putExtra("pk", pk);
        intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent2);         

    WakeLocker.release();
}}

WakeLocker

public static void acquire(Context ctx) {

if (wakeLock != null) wakeLock.release();

PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |  PowerManager.ACQUIRE_CAUSES_WAKEUP |
            PowerManager.ON_AFTER_RELEASE, "my tag");
    wakeLock.acquire();
}
public static void release() {
    if (wakeLock != null) wakeLock.release(); wakeLock = null;
}
}

设置警报

    Intent intent = new Intent(SETALARM.this, ALARMRECEIVER.class);
    intent.putExtra("pk", pk);
    sender = PendingIntent.getBroadcast(this, pk, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),60000, sender);

权限

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

The following works fine when the device is not asleep, however if I turn the device off - it does not wake up at the specified time.

Did I possibly miss something? Thanks in advance for your help.

onReiceive

@Override
public void onReceive(Context context, Intent intent) {         
    WakeLocker.acquire(context);  

        pk = Integer.parseInt(intent.getExtras().get("pk").toString());     
        Intent intent2 = new Intent(context,ALERT.class);
        intent2.putExtra("pk", pk);
        intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent2);         

    WakeLocker.release();
}}

WakeLocker

public static void acquire(Context ctx) {

if (wakeLock != null) wakeLock.release();

PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |  PowerManager.ACQUIRE_CAUSES_WAKEUP |
            PowerManager.ON_AFTER_RELEASE, "my tag");
    wakeLock.acquire();
}
public static void release() {
    if (wakeLock != null) wakeLock.release(); wakeLock = null;
}
}

Setalarm

    Intent intent = new Intent(SETALARM.this, ALARMRECEIVER.class);
    intent.putExtra("pk", pk);
    sender = PendingIntent.getBroadcast(this, pk, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),60000, sender);

Permission

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来分手还会想你 2025-01-13 13:49:18

根据Android开发者的说法。

注册的闹钟会在设备休眠时保留(如果闹钟在此期间关闭,则可以选择唤醒设备),但如果关闭并重新启动,则会清除该闹钟。

因此,如果设备关闭,您的警报管理器已被清除。

你可以参考这个网站。 http://developer.android.com/reference/android/app/AlarmManager.html

Based on the Android developers, there had been stated.

Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

So, your alarm manager has been cleared if the device is turned off.

You can refer this website. http://developer.android.com/reference/android/app/AlarmManager.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文