Skip to content Skip to sidebar Skip to footer

Android Activity Not Getting Broadcast From Local Service

From the examples this looked straightforward. Maybe you can show me what I did wrong. I can't get an activity to receive a broadcast sent from a local service. I have Activity1 th

Solution 1:

Eureka! I found it! The problem is that I supplied a data URI in my broadcast intent. The Android intent matching rules get a little complicated. If you supply a data URI, then your intent filter must specify a matching MIME type.

Unfortunately, although the Android documentation says that the data type can be inferred from the data URI, apparently Android doesn't know that a file://.../example.jpg is an image. So this doesn't work:

intentFilter.addDataType("image/*");

However, instead of specifying a type, I can specify a scheme that I accept:

intentFilter.addDataScheme("file");

That works! It's a little rough---and a little artificial to restrict my broadcasts to file: URIs, but as that's all I'm using for the moment, it works.

Note that apparently I could manually specify the MIME type in the intent when I broadcast it, but that's too much trouble for now, as I'm downloading images from Picasa so I already know that they are images (and don't care the specific MIME type). And if it gets too much trouble, I could ditch the whole setData() thing altogether and set an extra---but of course I want to do things the Right Way.

Solution 2:

have you included your receiver in your activity's manifest?

<receiverandroid:name=".YourReceiver"><intent-filter><actionandroid:name="intent_name"></action></intent-filter></receiver>

Post a Comment for "Android Activity Not Getting Broadcast From Local Service"