Questions tagged [broadcastreceiver]

BroadcastReceiver is an Android component that responds to system-wide broadcast announcements.

BroadcastReceiver is an Android component that responds to system-wide broadcast announcements.

Many broadcasts originate from the system – for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured.

Applications can also initiate broadcasts – for example, to let other applications know that some data has been downloaded to the device and is available for them to use.

Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.

For more information visit the Android BroadcastReceiver reference or the documentation for the receiver element used in the Android manifest file.

8368 questions
479
votes
13 answers

How to use LocalBroadcastManager?

How to use/locate LocalBroadcastManager as described in google docs and Service broadcast doc? I tried to google it, but there is no code available to start with? The documents say that I should use it if I want to do broadcast internally with in my…
waqaslam
  • 67,549
  • 16
  • 165
  • 178
344
votes
15 answers

Trying to start a service on boot on Android

I've been trying to start a service when a device boots up on android, but I cannot get it to work. I've looked at a number of links online but none of the code works. Am I forgetting something? AndroidManifest.xml
Alex
  • 3,767
  • 5
  • 19
  • 10
311
votes
7 answers

Get Context in a Service

Is there any reliable way to get a Context from a Service? I want to register a broadcast receiver for ACTION_PHONE_STATE_CHANGED but I don't need my app to always get this information, so I don't put it in the Manifest. However, I can't have the…
user123321
  • 12,593
  • 11
  • 52
  • 63
289
votes
17 answers

How to check if Receiver is registered in Android?

I need to check if my registered receiver is still registered if not how do i check it any methods?
Mikey
  • 4,218
  • 3
  • 25
  • 25
273
votes
21 answers

Broadcast receiver for checking internet connection in android app

I am developing an Android broadcast receiver for checking the internet connection. The problem is that my broadcast receiver is being called two times. I want it to get called only when the network is available. If it is unavailable, I don't want…
Nikhil Agrawal
  • 26,128
  • 21
  • 90
  • 126
268
votes
9 answers

How do I start my app when the phone starts on Android?

I tried using the sample code in this tutorial but it seems outdated and it did not work. So what changes do I have to make and to what files to have my app start automatically when Android finishes booting up?
Poojan
  • 3,312
  • 4
  • 20
  • 23
165
votes
10 answers

Programmatically register a broadcast receiver

I'd like to know what is the best practice/way of programmatically register a broadcast receiver. I want to register specific receivers according to user choice. As the registration is done through the manifest file, I'm wondering if there's a…
CoolStraw
  • 5,282
  • 8
  • 42
  • 64
137
votes
3 answers

BroadcastReceiver with multiple filters or multiple BroadcastReceivers?

I have an Android Activity that needs to catch two different broadcasts. My current approach is to have a single BroadcastReceiver within the Activity and catch both the broadcasts with it: public class MyActivity extends Activity { private…
Lorenzo Polidori
  • 10,332
  • 10
  • 51
  • 60
134
votes
6 answers

Sending and Receiving SMS and MMS in Android (pre Kit Kat Android 4.4)

I have figured out how to send and receive SMS messages. To send SMS messages I had to call the sendTextMessage() and sendMultipartTextMessage() methods of the SmsManager class. To receive SMS messages, I had to register a receiver in the…
Etienne Lawlor
  • 6,817
  • 18
  • 77
  • 89
131
votes
6 answers

Android - Start service on boot

From everything I've seen on Stack Exchange and elsewhere, I have everything set up correctly to start an IntentService when Android OS boots. Unfortunately it is not starting on boot, and I'm not getting any errors. Maybe the experts can…
Gady
  • 4,935
  • 8
  • 38
  • 48
127
votes
4 answers

Does BroadcastReceiver.onReceive always run in the UI thread?

In my App, I create a custom BroadcastReceiver and register it to my Context manually via Context.registerReceiver. I also have an AsyncTask that dispatches notifier-Intents via Context.sendBroadcast. The intents are sent from a non-UI worker…
Hannes Struß
  • 1,560
  • 2
  • 13
  • 20
122
votes
11 answers

Receiver not registered exception error?

In my developer console people keep reporting an error that I cannot reproduce on any phone I have. One person left a message saying he gets it when they try to open the settings screen of my battery service. As you can see from the error it says…
tyczj
  • 71,600
  • 54
  • 194
  • 296
103
votes
8 answers

Android, Detect when other apps are launched

I'm trying to develop an app that prevents a user from getting to a specified app without a password. The scenario is... user clicks on "Email" app (for example) my app detects launch of an app my app confirms it is the "Email" app my app opens a…
Ian
  • 1,243
  • 2
  • 11
  • 14
92
votes
2 answers

Broadcast Receiver within a Service

I am trying to start up a BroadcastReceiver within a Service. What I am trying to do is have a background running service going that collects incoming text messages, and logs incoming phone calls. I figured the best way to go about this is to have a…
Utopia025
  • 1,181
  • 3
  • 11
  • 21
86
votes
3 answers

Android - Getting context from a Broadcast receiver onReceive() to send to

I basically want to make an intent and pass it to a service from my BroadcastReceiver's onReceive(). So far I always used View.getContext(), but here, I'm stuck. How exactly can I get the context so I can use public Intent (Context packageContext,…
madu
  • 5,232
  • 14
  • 56
  • 96
1
2 3
99 100