How to keep CPU from 'sleeping' when screen is turned off in Android?

前端 未结 2 715
无人共我
无人共我 2020-12-31 05:32

I have an application in which I am sending network data over WiFI. Everything is fine until I turn the display off or the device goes to \'sleep\'. I\'m already locking th

2条回答
  •  不知归路
    2020-12-31 06:09

    Grab a PARTIAL_WAKE_LOCK from the PowerManager. You'll also need to add the WAKE_LOCK permission to your manifest.

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Tag"); 
    wl.acquire();
    //do what you need to do
    wl.release(); 
    

提交回复
热议问题