是使用WakeLock大材小用,而使用WifiLock在Android? [英] Is using WakeLock overkill while using WifiLock on Android?

查看:477
本文介绍了是使用WakeLock大材小用,而使用WifiLock在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的音频流应用程序工作正常,只有WifiLock。

My audio streaming app is working correctly with only WifiLock.

但有些设备报告说,当他们关闭屏幕,连接被切断,音频流被突破。 (他们,他们不这样做对3G)

But some devices report that when they turn off the screen, connection is cut and audio streaming is topped. (They they this does not happen on 3G)

所以,我想,也许我也可以使用部分WakeLock。我不知道这是否解决了问题,但我认为这是一个选项。同时,加入了WakeLock而基本WifiLock正可消耗电池更快,可能没有解决问题。

So, I thought maybe I can also use a 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.

你怎么看待添加WakeLock过这类问题,应用程序做?

What do you think about adding a WakeLock too for this kind of issue and app?

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我获取和创建的服务,并在它的破坏释放这些锁。)

(ofcourse I acquire and release these locks on the creation of the service and on the destruction of it.)

推荐答案

使用它们。我敢肯定的行为,从电话到不同的手机。你不妨搜索报告是有关+无线或WiFi驱动程序的设备。你确定你的音频流应用程序工作正常,只有WifiLock 的?这听起来很奇怪 - 在CPU的将会的去睡觉,该服务将停止 - 见的服务,WakeLock 。有些东西是保持手机清醒。所以你需要一个唤醒锁

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". Are you sure your audio streaming app is working correctly with only WifiLock ? This sounds very strange - the CPU will go to sleep and the service will stop - see Service, WakeLock. Something else is keeping the phone awake. So you need a wake lock

如果你只在另一方面使用唤醒锁则会关闭WiFi,也许 - 我不知道你正在使用它 - 但是有备无患。如果它关闭唤醒电话了也不会醒起来 - 为了这个,我敢肯定。使用无线网络锁对电池没有影响 - 使用WiFi无线电有,这你正在做的呢

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. 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.

因此​​,无论 - 并确保你的服务获得他们 - 看看 WakefulIntentService

So both - and be sure your service acquires them - have a look at WakefulIntentService

这篇关于是使用WakeLock大材小用,而使用WifiLock在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆