2

I'm trying to develop a Multicast application for 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. I'm running this as a service.

AndroidManifest.xml defenition for the service:

<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

(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

Joe Simpson
  • 2,546
  • 4
  • 30
  • 46

2 Answers2

3

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

  • and that the phone did not go to sleep before the wake.acquire() line is executed (use boolean bool = wake.isHeld(); to check it).
Aleadam
  • 40,203
  • 9
  • 86
  • 108
3

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)

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

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

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.

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. If you use a 3rd party firmware (ie. Cyanogen), then multicasting works fine.

Off the top of my head - here's a few that I know work / don't work

  • HTC Incredibe (Can't receive)
  • Nexus One (OK)
  • Nexus S (OK)
  • Motorola Droid / Droid Pro (OK)
Community
  • 1
  • 1
debracey
  • 6,517
  • 1
  • 30
  • 56