android - 在 sleep 模式下未收到 UDP 广播数据包

标签 android android-wifi android-networking

我的 Android 应用程序定期在 WiFi LAN 上发送和接收 UDP 广播消息。当显示屏打开时,一切正常,所有消息都可以正确发送和接收。然而,当显示器进入休眠状态时,应用程序将停止接收 UDP 广播消息(但仍会发送它们)。

获取 WiFiLock(以及多播锁)似乎没有任何区别,我的 wifi sleep 策略设置为 WIFI_SLEEP_POLICY_NEVER。

这是 Android 2.3.3 和 2.3.5(Samsung galaxy SII 手机)上的问题,但不是运行 cyanogen mod 和 android 2.3.7 的旧 HTC Hero 的问题。

有没有其他人遇到过这个问题并找到了解决方案?

最佳答案

这个 Google 网上论坛帖子处理这个问题:

https://groups.google.com/forum/?fromgroups=#!topic/android-platform/OpbSdp9FTmA

这与某些芯片组和深度 sleep 有关。基本上,驱动程序检测设备何时进入深度 sleep 并关闭 UDP 广播接收。根据我的经验,UDP 发送仍然有效,并且设备上的 UDP 发送/监听也将听到数据包,但这是一个幽灵,设备实际上是聋的。

下面的推荐是我用的:

  1. Acquire a PARTIAL_WAKE_LOCK, and trap when the screen goes off. Then disable and reenable the wifi. This works because the filter only turns on when the screen goes off, so starting wifi with the screen off will keep it working until the screen goes off again. This is what we did before we figured out solution (1).

关于android - 在 sleep 模式下未收到 UDP 广播数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9363389/

相关文章:

android - webview.java 中的 NullPointerException (android.webkit.WebView$PrivateHandler.handleMessage)

android - 隐藏 PreferenceFragment 上的选项菜单

java - 以编程方式打开 wifi 网络共享

Android使用改造后的方法将照片发送到服务器

android - 在 ubuntu 上设置安卓

java.lang.NullPointerException : Attempt to invoke virtual method 'android.view.View .MainActivity.findViewById(int)' on a null object reference 异常

android - 为什么 setWifiEnabled 为 CHANGE_NETWORK_STATE 权限抛出 SecurityException?

java - wifiSetEnabled(true) 有时不起作用

android - wpa_supplicant 是针对 android 设备特定的还是特定于 android 版本的?

java - 具有多个 Activity 网络的 Android NetworkInfo 状态