I have implemented a NotificationListenerService, yet it is not working. Here is the service:
public class NotificationListener extends NotificationListenerService {
@Override
public void onCreate() {
Log.d("MYAPP", "Created");
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.d("MYAPP", "Notification");
}
}
I have implemented this in my manifest file:
<service android:name="com.rodrigopontes.whatsappbubbles.NotificationListener"
android:label="Test"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
This is how I initialize it from my MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
startService(new Intent(this, NotificationListener.class));
}
Thank you for the help!
To use NotificationListenerService, we need to create a java file which extends NotificationListenerService and implement two callback methods. Both methods have a parameter named “sbn”, which is an object of StatusBarNotification class. StatusBarNotification provides necessary information about Notifications.
↳ android.service.notification.NotificationListenerService. A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
After many wasted hours I found the answer for this. This is an issue with Android see here Welcome to Android :)
I had the same problem. It turned out my app was not allowed to receive notification as it did not have permission. So I enabled the notification permission by following-
Intent intent=new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(intent);
Above code opens a notification permission page then select your app and allow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With