Questions tagged [android-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.

859 questions
4
votes
0 answers

How to use BroadcastReceiver in MVVM architecture in Android?

I can think of 2 options but neither of them sounds best-practice : Extending LiveData. But then it would hold a reference to Context, and as Google states this is a very bad design to hold any reference to Views or Context inside…
BVtp
  • 2,308
  • 2
  • 29
  • 68
4
votes
1 answer

NativeScript background service stops working after app closes

I have problem with nativescript background service. I want to write application with background service. The service must be always run in background, even when the application will be stoped and closed. I have used nativescript-android-utils for…
4
votes
3 answers

Sending notification via AlarmManager and BroadcastReceiver does not work?

I'm scheduling a notification for 5 days ahead, so I create an alarm using the AlarmManager who fires a PendingIntent which triggers my BroadcastReceiver. If I try the code for 10 seconds, it works. When I try it for 5 days, nothing happens. The…
4
votes
3 answers

android.net.wifi.STATE_CHANGE or android.net.wifi.supplicant.CONNECTION_CHANGE

In android broadcasts, what's the difference between and
Yesudass Moses
  • 1,841
  • 3
  • 27
  • 63
4
votes
2 answers

How to generate notification when a new picture is taken by camera app?

I want to create a notification from my app when a new picture is taken from the camera app. I want to achieve this when my app is not running. I am using Broadcast receiver to do this. Here is my Code... In Android Manifest..
4
votes
1 answer

synchronized block inside onReceive() callback

I am reading this page about how to program Android to talk to a USB accessory. One of the steps involves registering a BroadcastReceiver to obtain permission from the user: IntentFilter filter = new…
4
votes
1 answer

java.lang.InstantiationException: class has no zero argument constructor error

I've read the other threads that exist but none of them have been able to solve my problem. I'm building an app which caches messages when there's no internet and stores them to a Database. The idea is when there is network connected, it pulls the…
4
votes
2 answers

How To Test BOOT_COMPLETED Broadcast Receiver

I want to check the BROADCAST RECEIVER with Action BOOT_COMPLETED in the emulator. This my code public class AutoRunService extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if…
4
votes
1 answer

Non protected broadcast causes crash on starting of app

I made a service for receiving notification, every time data is updated at the back end. Here's the code for the service: public class FeedbackService extends IntentService { public FeedbackService() { …
4
votes
1 answer

Android - ConnectivityManager.EXTRA_NETWORK_INFO deprecated

I am creating a BroadcastReceiver to listen for Wi-Fi connectivity changes: registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if…
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
4
votes
1 answer

Unable to send android.intent.action.BOOT_COMPLETED from adb shell

I am building an app, which needs to start a service automatically when the device boots up. I want to test this functionality with adb. When I issue the following command from adb adb shell am broadcast -a android.intent.action.BOOT_COMPLETED I…
samsri
  • 1,104
  • 14
  • 25
4
votes
2 answers

Which context does BroadcastReceivers receive when listening for BOOT_COMPLETED?

AlarmManagers in Android lose all of their registered alarms when phone loses power. I use the following broadcast receiver to trigger at android bootup: public class AlarmBootReceiver extends BroadcastReceiver { @Override public void…
4
votes
0 answers

How to tell if broadcast received Android

I'm creating a shortcut by sending out this broadcast. Intent shortcutIntent = new Intent(this, AuthenticationActivity.class); // create the broadcast final Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); …
4
votes
0 answers

Android: Should I use BroadcastReceiver vs Messenger vs BindService vs Handler

I know this look like tons of question around SO. But it's not (although I can also be wrong). I have a long running Service (running in a separate thread using blutooth socket pooling for data in a OBD2 adapter every 5 seconds). This Service is…
4
votes
1 answer

java.lang.RuntimeException: Unable to instantiate receiver (Didn't find class)

We are using a 3rd party library for ad mediation that declares different activities, receivers and services in its manifest. Not all of these are going to actually be implemented in the app. I have started seeing exceptions such as this one from…