How to use CPU to perform any operation in Deep Sleep mode

前端 未结 2 914
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 02:43

I\'m new in android. I struggle with my application approximately 3 weeks. I need sent and receive packets in normal mode and sleep mode. My

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 03:42

    Even RTC_WAKEUP doesn't help most of the times.

    Solution that worked for my app when device in deep sleep mode:
    Use WakefulBroadcastReceiver combined with AlarmManager.

    Service is started by startWakefulService() and when it is finished, it releases the wake lock by calling completeWakefulIntent(intent). So the device will be allowed to go back to sleep.

    I'm not adding any code. Search for examples on how to use WakefulBroadcastReceiver with AlarmManager. Even WakefulBroadcastReceiver doc has some template code.

    Also reduce the frequency of alarm so you can avoid draining so much battery.

提交回复
热议问题