Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:08:22+00:00 2026-05-26T22:08:22+00:00

From the examples this looked straightforward. Maybe you can show me what I did

  • 0

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 that start Service1:

startService(new Intent(Activity1.this, Service1.class));

Activity1 then starts Activity2:

startActivity(new Intent(Activity1.this, Activity2.class));

Service1, a local service, listens for downloads:

protected final BroadcastReceiver service2DownloadBroadcastReceiver = new BroadcastReceiver()
{
    public void onReceive(final Context context, final Intent intent)
    {
        ...
        broadcastDownloadFinished(Uri.fromFile(downloadedFile));

The broadcast receiver of Service1 then broadcasts its own message:

protected Intent broadcastDownloadFinished(final Uri uri)
{
    final Intent intent = new Intent(ACTION_DOWNLOAD_FINISHED).setData(checkNotNull(uri));
    sendBroadcast(intent);

Activity2, which is in the foreground at the time, listens for the ACTION_DOWNLOAD_FINISHED intent using its own broadcast receiver:

private final BroadcastReceiver activity2DownloadBroadcastReceiver = new BroadcastReceiver()
{
    public void onReceive(final Context context, final Intent intent)
    {
        Log.i(Activity2.class.getSimpleName(), "Received download event: " + intent.getAction() + " " + intent.getData());

Activity2 of course registers the receiver:

protected void onResume()
{
    super.onResume();
    final IntentFilter downloadIntentFilter = new IntentFilter();
    downloadIntentFilter.addAction(ACTION_DOWNLOAD_FINISHED);
    registerReceiver(activity2DownloadBroadcastReceiver, downloadIntentFilter);

In case it matters, ACTION_DOWNLOAD_FINISHED is something like "com.example.intent.action.DOWNLOAD_FINISHED".

Service1 receives the download manager event in its receiver and apparently broadcasts its own custom event, but Activity2 never seems to receive it. What did I do wrong? Is it a problem to broadcast an intent in the middle of processing another one? (I wouldn’t think so—this is asynchronous, right?)

Update: Just to make sure there is no problem sending a broadcast in the middle of receiving a broadcast, I changed my broadcast code to actually perform the broadcast three seconds later on the main thread:

    Log.i(getClass().getSimpleName(), "...ready to broadcast");     
    final Intent intent = new Intent(ACTION_DOWNLOAD_FINISHED).setData(checkNotNull(uri));
    mainThreadHandler.postDelayed(new Runnable()
    {
        public void run()
        {
            Log.i(getClass().getSimpleName(), "...broadcasting");
            sendBroadcast(intent);
            Log.i(getClass().getSimpleName(), "...broadcasted");                
        }
    }, 3000);
    Log.i(getClass().getSimpleName(), "...scheduled to broadcast");

As expected, the log says:

...ready to broadcast
...scheduled to broadcast
...broadcasting
...broadcasted

Yet nothing is received in the activity. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:08:22+00:00Added an answer on May 26, 2026 at 10:08 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't seem to find any examples of this being done from the activity. I
I looked at this example from the C# in nutshell book ( http://www.albahari.com/nutshell/ch04.aspx )
from this site there is header compress.h http://www.fredosaurus.com/notes-cpp/examples/compress/compress.html i am using visual c++ 2010
All examples are taken from the SICP Book: http://sicpinclojure.com/?q=sicp/1-3-3-procedures-general-methods This was motivated from the
I have looked all over for pthread_join examples, I am having troubles debugging this
im having difficulties figuring this out, ive looked at examples here and on the
I'm trying to get the examples from Linux Device Drivers, ed 3 (ldd3) working
From this example http://www.senchafiddle.com/#dPZn0 This displays a first panel, then a second one... using
With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.