How to read all the coming notifications in android

First you must declare your intent to receive notifications in your manifest, so that you can get the android.permission.BIND_NOTIFICATION_LISTENER_SERVICE permission. AndroidManifest.xml: <service android:name=”.NotificationListener” android:label=”@string/service_name” android:permission=”android.permission.BIND_NOTIFICATION_LISTENER_SERVICE”> <intent-filter> <action android:name=”android.service.notification.NotificationListenerService” /> </intent-filter> </service> Then create a NotificationListenerService class and override the onNotificationPosted function. For more information, read the developer reference here: https://developer.android.com/reference/android/service/notification/NotificationListenerService.html Also look at this simple … Read more

Using a broadcast intent/broadcast receiver to send messages from a service to an activity

EDITED Corrected code examples for registering/unregistering the BroadcastReceiver and also removed manifest declaration. Define ReceiveMessages as an inner class within the Activity which needs to listen for messages from the Service. Then, declare class variables such as… ReceiveMessages myReceiver = null; Boolean myReceiverIsRegistered = false; In onCreate() use myReceiver = new ReceiveMessages(); Then in onResume()… … Read more

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

How to setup Alertbox from BroadcastReceiver

Although you can not show AlertDialog from Receivers because it needs ActivityContext. You have an alternate solution to show an Activity like AlertDialog from Receiver. This is possible. To start Activity as dialog you should set theme of activity in manifest as <activity android:theme=”@android:style/Theme.Dialog” /> Style Any Activity as an Alert Dialog in Android To … Read more

Boot BroadcastReceiver does not work on Xiaomi devices

I searched around the web and found a solution, I’ve decided to answer my own question. Follow the same code given in the question. In Xiaomi devices, you just have to add your app to Autostart list, to do so, follow these simple steps given below: Open Security app on your phone. Tap on Permissions, … 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

Communication between BroadcastReceiver and Activity – android

You can use observers , like public class MyReceiver extends BroadcastReceiver { public MyReceiver() { } @Override public void onReceive(Context context, Intent intent) { ObservableObject.getInstance().updateValue(intent); } } public class MainActivity extends Activity implements Observer { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ObservableObject.getInstance().addObserver(this); } @Override public void update(Observable observable, Object data) { Toast.makeText(this, String.valueOf(“activity observer … Read more

How to detect Bluetooth state change using a broadcast receiver?

AS far as permissions go, to detect the state change of bluetooth you need to add this to your AndroidManifest.xml. <uses-permission android:name=”android.permission.BLUETOOTH” /> An example receiver would look like this, you add this code to where you want to handle the broadcast, for example an activity: private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public … Read more