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
84
votes
5 answers

Service Intent must be explicit: Intent

I have an app some time now in which I call a service through a broadcast receiver (MyStartupIntentReceiver). The code in the broadcast receiver in order to call the service is: public void onReceive(Context context, Intent intent) { Intent…
duk3r
  • 1,174
  • 2
  • 12
  • 16
83
votes
5 answers

When to Register/Unregister Broadcast Receivers created in an activity?

I have a need to create a custom broadcast receiver in the onCreate event of an activity and obviously I need to unRegister the broadcast receiver in the onDestroy event of the activity For clarity this is a snippet of the code I use public class…
jamesc
  • 12,423
  • 15
  • 74
  • 113
81
votes
1 answer

Should I use android: process =":remote" in my receiver?

I have a BroadcastReceiver which is called every so often, and I have noticed many people use android: process =":remote" in their receiver. Mine is used to check a few things and if the conditions match then activate an alarm. My question is…
Jason
  • 4,034
  • 4
  • 40
  • 62
78
votes
7 answers

Starting Service from BroadcastReceiver

I have a Service and BroadcastReceiver in my application, but how do I launch the service directly from the BroadcastReceiver? Using startService(new Intent(this, MyService.class)); does not work in a BroadcastReceiver, any…
Samuel
  • 4,337
  • 3
  • 29
  • 35
78
votes
4 answers

Registering and unregistering BroadcastReceiver in a fragment

My app has an action bar with 3 fragment tabs. In the second fragment I register and unregister a BroadcastReceiver. I unregister the receiver in onPause and register it in onCreateView and in…
Natasha
  • 1,470
  • 5
  • 18
  • 24
75
votes
2 answers

Broadcast Receiver Register in Manifest vs. Activity

I need some help to understand when I can expect my broadcast receiver will work when just registered in the manifest versus having to be registered from a running activity or service. So for example if I register a stand alone receiver with the…
ControlAltDelete
  • 3,576
  • 5
  • 32
  • 50
74
votes
9 answers

BroadcastReceiver not receiving BOOT_COMPLETED

I've looked around here for similiar problems, but for some reason my BroadcastReceiver never ends up receiving the android.intent.action.BOOT_COMPLETED Intent. Here is my (relative) Android.Manifest File:
apmeyers1987
  • 859
  • 1
  • 7
  • 11
74
votes
9 answers

Sending intent to BroadcastReceiver from adb

I've got BroadcastReceiver class: public class IntentReceiver extends BroadcastReceiver { final String tag = "Intent Intercepter"; @Override public void onReceive(Context context, Intent intent) { try { String data…
user2106655
  • 1,121
  • 1
  • 9
  • 10
73
votes
2 answers

android: broadcast receiver for screen on and screen off

I was just wondering if it is possible to register a broadcast receiver that detects Screen ON/OFF in the application manifest. The reason why I don't like the programmable method is that it requires the app to be running in order to detect such a…
himura
  • 1,555
  • 3
  • 19
  • 30
72
votes
9 answers

How to fix BOOT_COMPLETED not working Android

I know there has been hundreds of this kind of question asked, but I've been checking them all for a while and still couldn't find any solution. I've seen this answer to "Android BOOT_COMPLETED not received when application is closed" said…
yahya
  • 4,810
  • 3
  • 41
  • 58
71
votes
13 answers

Check INTENT internet connection

Is there an Android Intent ACTION_XXX that notifies me when an Internet Connection is available? I want to instantiate a BroadcastReceiver that notifies my application when a user enables Internet Connection (by wifi, by GSM, etc.) Could anyone help…
CeccoCQ
  • 3,746
  • 12
  • 50
  • 81
70
votes
5 answers

android - How to get view from context?

I want to get the view or findViewById() from Context? Or from intent? I'm trying to reach a specific view in my broadcast receiver and the parameter of onReceive are context and intent. Well, I have a class and within it is my broadcast receiver. …
lorraine batol
  • 6,001
  • 16
  • 55
  • 114
65
votes
2 answers

What is the use of android:exported="true" in BroadcastReceiver

I see that some broadcast receiver use this tag android:exported="true" in Android Manifest.xml to register.
N Sharma
  • 33,489
  • 95
  • 256
  • 444
65
votes
5 answers

Determine addAction click for Android notifications

I'm trying to use the new notifications interface. I've added 3 buttons to the notifications, and I want to save something to my database once each of them is clicked. The notification itself works well and is shown when called, I just don't know…