1

好的,我编写了一个发送和接收多播 UDP 数据包的应用程序。该应用程序在我的三星 S3 上运行良好,但在运行 Android 2.3.5 的 HTC Explorer 上没有收到任何数据包。在进一步的研究中,我发现有些手机完全不支持 UDP 多播。我想确保我的应用程序适用于所有手机。我们可以在 HTC 手机上启用多播吗?如果没有,这个问题还有其他解决方案吗?

4

1 回答 1

0

我在运行 Android 4.1.2 的 HTC One 上遇到了同样的问题

这是一个从Android 错误报告中为我解决的解决方案:

Wanting to receive broadcasts in a async routine I now use the following code just before the loop where the broadcast messages are received:

WifiManager wifi;
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock ml = wifi.createMulticastLock("just some tag text");
ml.acquire();

When the asynctask stops I do a 
ml.release();

我还必须在 AndroidManifest.xml 中包含以下内容:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
于 2013-08-02T00:18:10.923 回答