NotificationListenerService not working - even after granting permission

Below is my code for capturing notifications. I do not understand why onNotificationPosted is not being fired.

I provide access to My Application Notifications from Settings> Security, and the onCreate from MyNotifService also starts, but onNotificationPosted does not start.

What am I missing or doing wrong?

From my MainActivity onCreate () function:

Intent intent = new Intent(this, MyNotifService.class); this.startService(intent); 

My Service Code that extends NotificationListenerService :

 @SuppressLint("NewApi") public class MyNotifService extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { super.onNotificationPosted(sbn); Log.v("focus", "in onNotificationPosted() of MyNotifService"); } @Override public void onCreate() { super.onCreate(); Log.v("focus", "in onCreate() of MyNotifService"); } } 

In the manifest file, I have this:

 <service android:name="com.mavdev.focusoutfacebook.notifications.MyNotifService" android:label="@string/app_name" android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" > <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service> 
+7
source share
1 answer

This seems like a bit of a mistake, but in this case this is the actual fix:

 @Override public IBinder onBind(Intent intent) { return super.onBind(intent); } 
+2
source

Source: https://habr.com/ru/post/979536/


All Articles