partial wakelock for 3G in Android

2019-06-02 00:51发布

I have a service that uploads file to a server. I acquire a wifilock on it but do I need a partial wakelock if the service is using 3G ?

2条回答
Viruses.
2楼-- · 2019-06-02 01:43

Yes. Otherwise, the device may fall asleep during your upload process.

查看更多
\"骚年 ilove
3楼-- · 2019-06-02 01:53

WakeLock is an Inefficient way of keeping the screen on. Instead use the WindowManager to do the magic. The following one line will suffice the WakeLock. The WakeLock Permission is not needed for this to work. Also this code is efficient than the WakeLock.

getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

You need not relase the WakeLock Manually. This code will allow the Android System to handle the Lock Automatically. When your application is in the Foreground then WakeLock is held and else android System releases the Lock automatically.

查看更多
登录 后发表回答