BroadcastReceiver Vs WakefulBroadcastReceiver

There is only one difference between BroadcastReceiver and WakefulBroadcastReceiver. When you receive the broadcast inside onReceive() method, Suppose, BroadcastReceiver : It is not guaranteed that CPU will stay awake if you initiate some long running process. CPU may go immediately back to sleep. WakefulBroadcastReceiver : It is guaranteed that CPU will stay awake until you … Read more

BroadcastReceiver for ACTION_MEDIA_BUTTON not working

I tested this on a Samsung Galaxy S5 with Android 4.4.2. So what is important and what is not mentioned in other posts: Register the receiver in the AndroidManifest.xml inside the application tag but outside from every activity tag. Your receiver Broadcastreceiver need to be public and static One activity need to register an MediaButtonEventReceiver … Read more

Capture media button on Android >=4.0 (works on 2.3)

Make sure that you have an activity in your app, and that the user runs this activity before attempting to press that button. Until then, your <receiver> will not receive any broadcasts. UPDATE On Android 4.0 and higher, it appears that you also need to call registerMediaButtonEventReceiver() on AudioManager in order to receive the events. … Read more

How can I send result data from Broadcast Receiver to Activity

You can call the receiver from your activity. If you don’t want to add the logic of the receiver in you activity you can use an abstract receiver. You abstract receiver: public abstract class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //Add you receiver logic here … … onNewPosition(); } … Read more

Can’t start activity from BroadcastReceiver on android 10

Android 10’s restriction on background activity starts was announced about six months ago. You can read more about it in the documentation. Use a high-priority notification, with an associated full-screen Intent, instead. See the documentation. This sample app demonstrates this, by using WorkManager to trigger a background event needing to alert the user. There, I … Read more