简体   繁体   English

在Android上使用WifiLock时使用WakeLock是否过度杀伤?

[英]Is using WakeLock overkill while using WifiLock on Android?

My audio streaming app is working correctly with only WifiLock. 我的音频流应用程序只能使用WifiLock正常工作。

But some devices report that when they turn off the screen, connection is cut and audio streaming is topped. 但有些设备报告说,当他们关闭屏幕时,连接会被切断,音频流也会突然出现。 (They say this does not happen on 3G) (他们说这不会发生在3G上)

So, I thought maybe I can also use a Partial WakeLock. 所以,我想也许我也可以使用Partial WakeLock。 I am not sure if this fixes the issue but I think it is an option. 我不确定这是否解决了这个问题,但我认为这是一个选择。 At the same time, adding a WakeLock while a basic WifiLock is working may deplete the battery faster and may not fix the issue. 同时,在基本WifiLock工作时添加WakeLock可能会更快耗尽电池并且可能无法解决问题。

What do you think about adding a WakeLock too for this kind of issue and app? 您对此类问题和应用程序添加WakeLock有什么看法?

private static WifiLock wifiLock = ((WifiManager) appInstance().getSystemService(Context.WIFI_SERVICE))
        .createWifiLock((android.os.Build.VERSION.SDK_INT>=12?WifiManager.WIFI_MODE_FULL_HIGH_PERF:WifiManager.WIFI_MODE_FULL), "myappwifilock");

The newly added line: 新添加的行:

private static WakeLock wakeLock= ((PowerManager) appInstance().getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "myappwakelock");

(ofcourse I acquire and release these locks on the creation of the service and on the destruction of it.) (当然,我在创建服务和销毁服务时获取并释放这些锁。)

Use them both. 两者都使用它们。 The behavior I am sure varies from phone to phone. 我确定的行为因手机而异。 You may wish to search for the devices the reports are about + "wifi"or "wifi driver". 您可能希望搜索报告所关注的设备+“wifi”或“wifi驱动程序”。 Are you sure your audio streaming app is working correctly with only WifiLock ? 你确定你的音频流应用程序只能与WifiLock一起正常工作吗? This sounds very strange - the CPU will go to sleep and the service will stop - see Service, WakeLock . 这听起来很奇怪 - CPU 进入睡眠状态,服务将停止 - 请参阅服务,WakeLock Something else is keeping the phone awake. 还有其他东西让手机保持清醒状态。 So you need a wake lock 所以你需要一个唤醒锁

If you only use wake lock on the other hand the wifi will turn off maybe - I am not sure for you are using it - but better safe than sorry. 如果你只使用唤醒锁,另一方面wifi也可能会关闭 - 我不确定你是否正在使用它 - 但更安全而不是抱歉。 If it does turn off waking the phone up won't wake it up - for this I am sure. 如果它确实关闭唤醒手机将不会唤醒它 - 为此我肯定。 Using the wifi lock has no impact on the battery - using the wifi radio has, and this you are doing anyway. 使用wifi锁定对电池没有影响 - 使用wifi收音机,无论如何你正在这样做。

So both - and be sure your service acquires them - have a look at WakefulIntentService 所以两者 - 并确保您的服务获得它们 - 看看WakefulIntentService

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM