Alarm Manager does not work in background on Android 6.0

后端 未结 3 1619
礼貌的吻别
礼貌的吻别 2020-12-05 15:53

This is my Activity code,

Long time = new GregorianCalendar().getTimeInMillis()+20000;//Setting alarm after 20 sec
Intent intentAlarm = new Inte         


        
3条回答
  •  无人及你
    2020-12-05 16:26

    The reason can be Doze mode introduced in Android 6.0 Marshmallow. Use setAlarmclock() instead of set(). It's designed specifically for alarm clocks and may be able to cut through doze. There are a few adb commands you can use to manually put a phone into doze or app standby mode:

    https://developer.android.com/preview/features/power-mgmt.html

    If that isn't able to wake your app up, there's the surefire method setExactAndAllowWhileIdle() is designed to wake the phone from doze no matter what. Worst case scenario, you can wake your app up with this method and use the wakeup to schedule the next alarm.

    Reference: How to make Alarm Manager work when Android 6.0 in Doze mode?

提交回复
热议问题