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
1 answer

Fatal Exception: java.lang.OutOfMemoryError: int[] of length 1083403672 exceeds the VM limit

Fatal Exception: java.lang.OutOfMemoryError: int[] of length 1083403672 exceeds the VM limit at android.util.ArrayMap.allocArrays(ArrayMap.java:196) at android.util.ArrayMap.ensureCapacity(ArrayMap.java:307) at…
4
votes
0 answers

AlarmManager triggers before scheduled time

I am trying to generate a notification after 10 minutes a particular button has been clicked.To do this I used AlarmManager and the NotificationManager classes. Below is my code MainActivity.java import android.app.AlarmManager; import…
4
votes
2 answers

Broadcast Receiver in an IntentService

I am trying to register the DownloadManager.ACTION_DOWNLOAD_COMPLETE receiver in onHandleIntent() method of my IntentService and unregistering the receiver in onDestroy() method of the IntentService. But I think its not getting registered, since the…
4
votes
1 answer

Trying to count number of times the phone is unlocked

i tired this a few months ago but failed. what i'm trying to do is count the number of times the user unlocks his phone and show it on the screen but i'm getting vague numbers each time i unlock the phone. my code is a follows. My main activity…
pavitran
  • 814
  • 1
  • 10
  • 25
4
votes
1 answer

Can't instantiate receiver: class has no zero argument

Although I know there are some answers out there already, I don't quite understand them as I am just a beginner in Android programming. I tried to instantiate my receiver using the following code:
user5404864
4
votes
0 answers

Why LocalBroadcastManager is not working in service?

I used Service and i am not recieving any broadcasted message. Need quick response. This is the intent filter string i used. public class AppConstant { public static final String FILTER = "com.sample.hmi.REQUEST_PROCESSED" ..... } My…
3
votes
3 answers

How can I update a var inside a whole kotlin class through a method and then retrieve it updated with another method call

I've written a kotlin class with an overridden fun and a fun to update a var into the class scope (I'm tragically new to Kotlin!) class mySampleClass: sampleReference(){ var varToBeUpdated:String = "my string" //var in class scope to be…
3
votes
1 answer

Why FileProvider not working with Broadcast?

I using FileProvider to generate an uri, then I want to pass it to BroadcastReceiver in another App, but I only get Exception of "Permission Denial: opening provider", how can I fix it? There's two app: Sender & Receiver, then Sender want to share a…
3
votes
0 answers

How to handle createChooser's IntentSender without having the component class of the receiver Intent

I am trying to handle the IntentSender of Intent.createChooser() to do something when a user selects an app to share an image on. Most the examples I've found here (posted below), require using a BroadcastReceiver as follows: Intent receiver = new…
3
votes
0 answers

BroadcastReceiver for shutdown is not triggering on programmatically rebooting the device

I have to reboot the device on specific time.i am using below code for that private void rebootAfterSomeTime() { h = new Handler(Looper.getMainLooper()); r = new Runnable() { public void run() { //current time …
Gaju Kollur
  • 2,046
  • 5
  • 23
  • 47
3
votes
2 answers

How do I detect network state /wifi state has changed while my app is in the background?

I am trying to figure out how do I detect wifi state change while my app is in the background. To give a summary of my issue. In my activity I register a receiver OnStart()such that : IntentFilter networkIntent = new IntentFilter(); …
3
votes
3 answers

Not receiving Intent.ACTION_MEDIA_MOUNTED in Android App in API 27 for USB flash drive

The following code was working on API 23, but it is not working on API 27. I read that there are some restrictions in Android API 26 and above for receiving Broadcast Intents but those are only for the ones specified in Manifest file : public class…
androidFan
  • 611
  • 2
  • 19
  • 31
3
votes
1 answer

Error receiving broadcast Intent on DownloadManager DOWNLOAD_COMPLETE Broadcast receiver

I'm getting following error when I try to get status of the downloaded file from the Android Download manager. E/AndroidRuntime: FATAL EXCEPTION: main Process: com.purelightaudio.healer, PID: 24201 java.lang.RuntimeException: Error receiving…
3
votes
2 answers

android BroadcastReceiver called twice

i am working on chat project what i did here is service with the connection staff and i set a broadcast receiver to get the data from the service this is the receiver code mMessageReceiver = new BroadcastReceiver() { @Override public…
3
votes
1 answer

How To Detect A Headset Plugged In on Android 8.0 with targetSDKVersion >= 26

Before Android 8.0, Oreo, you could detect a headset plugged in with a background service with a registered broadcast. With Android O's background execution limits, you can no longer do this without a notification. While ACTION_HEADSET_PLUG is an…
Justin
  • 3,322
  • 2
  • 22
  • 37