Service pauses on screen lock

前端 未结 3 609
说谎
说谎 2021-01-26 19:02

For testing purposes i have made a service that beeps every 1 minute. (No client-server interface yet). It beeps okay when the screen in on, but when it goes to sleep the beepin

3条回答
  •  花落未央
    2021-01-26 19:30

    This finally worked for me. Download the CWAC-WakefulIntentService.jar from https://github.com/commonsguy/cwac-wakeful

    add a class in your project

    import com.commonsware.cwac.wakeful.WakefulIntentService;
    
    public class WakeService extends WakefulIntentService {
    
        public WakeService(String name) {
    
            super(name);
    
        }
        @Override
        protected void doWakefulWork(Intent intent) {
        }
    }
    

    now add the following line in your code where ever you want to repeat the loop and wake the device up

    WakefulIntentService.sendWakefulWork(this, S_WS_WakeService.class);

提交回复
热议问题