简体   繁体   English

屏幕关闭时,Android上的多播不想工作

[英]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: 显而易见的是:

  • Make sure you set the permissions in the manifest: 确保在清单中设置权限:

<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" />

  • and that the phone did not go to sleep before 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 我的头顶上-我知道一些工作/不工作

  • HTC Incredibe (Can't receive) HTC Incredibe(无法接收)
  • Nexus One (OK) Nexus One(确定)
  • Nexus S (OK) Nexus S(确定)
  • Motorola Droid / Droid Pro (OK) 摩托罗拉Droid / Droid Pro(确定)

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

相关问题 屏幕关闭时,倒计时器无法正常工作 - When the screen turns Off, the countdowntimer doesn't work properly UDP组播在两台不同的PC上均不起作用 - UDP Multicast doesn't work in 2 different PCs 我希望Android进度对话框一直显示在屏幕上,直到新活动的功能完成但不起作用 - I want Android progress dialog to stay on screen until function on new activity is complete but doesn't work Xamarin Android-启动屏幕无法在恢复中正常工作 - Xamarin Android - Splash Screen Doesn't Work On Resume 我想在单击按钮1时打印数字1,但它不起作用 - I want to print number 1 when click the button 1 but it doesn't work 弹出屏幕不起作用 - Popup Screen doesn't work 当我在 java 中提高速度时,我的球不会从屏幕边缘反弹 - My ball doesn't bounce off the edge of screen when I up it's speed in java 在所有android设备上关闭屏幕后,其他类型的传感器(加速度计除外)还能工作吗? - do other kinds of sensors(except accelerometer)work when the screen is off on all android devices? 屏幕关闭时的Android音量按钮监听器 - Android Volume Button Listener when Screen Off 屏幕关闭时Android应用视频录制 - Android app video recording when screen off
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM