[英]Multicast on Android doesn't want to work when the screen is off
I'm trying to develop a Multicast application for Android. 我正在尝试为Android开发一个多播应用程序。 It works however, when the screen is turned off, it doesn't.
但是,当屏幕关闭时,它不起作用。 I know it's not my device as Winamp works fine when the screen is off.
我知道这不是我的设备,因为关闭屏幕后Winamp可以正常工作。 I'm running this as a service.
我将其作为服务运行。
AndroidManifest.xml defenition for the service: 服务的AndroidManifest.xml定义:
<service android:exported="true" android:name="AndroidRocketService"></service>
Java code for the service: http://tinypaste.com/c569a/fullscreen.php?hash=e7495a255a33a99ea8cc48bf24ea2b01&toolbar=true&linenum=true 服务的Java代码: http : //tinypaste.com/c569a/fullscreen.php?hash = e7495a255a33a99ea8cc48bf24ea2b01&toolbar = true&linenum = true
(The application will be open source when it works, so I'm not bothered about posting the whole thing non-working) (该应用程序在工作时将是开源的,因此我不必担心整个程序都无法正常工作)
Thanks in advance, 提前致谢,
Joe 乔
The obvious ones: 显而易见的是:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
the wake.acquire()
line is executed (use boolean bool = wake.isHeld();
to check it). the wake.acquire()
行之前电话没有进入睡眠状态(使用boolean bool = wake.isHeld();
进行检查)。 Aleadam's answer is correct. 阿利丹的答案是正确的。 You also need to make sure that you acquire the multicast locks as mentioned in the comments and at:
您还需要确保您已获得注释和下面提到的多播锁:
Android Multicast socket stops listening << Look at Erich's answer (not the accepted one) Android Multicast套接字停止监听 <<看Erich的答案(不是公认的答案)
The much larger problem is that, prior to Gingerbread, Android did not follow the proper standards with its multicast algorithms, as noted in several (angry) exchanges with Google developers here . 更大的问题是,在Gingerbread之前,Android并未遵循其多播算法遵循适当的标准,正如在此处与Google开发人员进行的几次(愤怒)交流中所指出的那样。 There's also another bug on their forums where pre Gingbread phones didn't due the multicast join properly -- but I can't find that one right now.
在他们的论坛上还有一个错误,即以前的Gingbread手机由于多播无法正确加入而无法正常运行-但我现在找不到那个错误。
The bottom line is that pre Gingbread phones set the TTL of the multicast packets to 1. So, if anything along the way decrements the TTL (usually some intermediate router) your packet will "die on the vine." 最重要的是,Gingbread之前的电话将多播数据包的TTL设置为1。因此,如果在此过程中有任何事情降低TTL(通常是一些中间路由器),您的数据包将“死在藤蔓上”。
Google posted a fix for the TTL bug in the post I linked, but to implement the fix you have to build your own custom kernel and deploy it to the phone. Google在我链接的帖子中发布了TTL错误的修复程序,但是要实施此修复程序,您必须构建自己的自定义内核并将其部署到手机中。
It's also worth noting, that several very popular phones don't do multicasting properly. 还值得注意的是,一些非常受欢迎的电话不能正确进行多播。 One that comes to mind is the HTC Incredible, which can send but cannot receive.
想到的一个是HTC Incredible,它可以发送但不能接收。 If you use a 3rd party firmware (ie. Cyanogen), then multicasting works fine.
如果您使用第三方固件(例如Cyanogen),则组播工作正常。
Off the top of my head - here's a few that I know work / don't work 我的头顶上-我知道一些工作/不工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.