android:报警不唤醒设备

时间:2012-02-19 02:16:29

标签: android alarmmanager

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

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

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);

权限

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

1 个答案:

答案 0 :(得分:-1)

基于Android开发人员,有人说过。

  

当设备处于睡眠状态时,会保留已注册的警报(如果设备在此期间关闭,则可以选择将设备唤醒),但如果设备关闭并重新启动,则会被清除。

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

您可以参考此网站。 http://developer.android.com/reference/android/app/AlarmManager.html