Android Question [SOLVED] Notification Listener stops catching notifications

GeoT

Active Member
Licensed User
Hi.
I am using the NotificationListener v. 1.20 to capture the notification data.
But I don't know why he doesn't always catch them.
I have it all with try and catch so that the service doesn't crash, but sometimes he is not called by the system it seems.

They already commented on it Notification Listener stops catching notifications

Has this problem already been solved?
Any ideas?

Thank you
 

GeoT

Active Member
Licensed User
Hi.
At the moment, I save the data of certain notifications in text files from the service, and I save the small icons if they don't exist in my app folder.

At the moment, the unfiltered log shows me

B4X:
Log reader error: java.io.InterruptedIOException: read interrupted
-1 received
writer error
java.lang.InterruptedException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2042)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2076)
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:387)
    at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:160)
    at java.lang.Thread.run(Thread.java:919)
Starting remote logger. Port: 59865
After accept
-1 received
writer error
java.net.SocketException: Socket closed
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:124)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:149)
    at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:161)
    at java.lang.Thread.run(Thread.java:919)
Log reader error: java.io.InterruptedIOException: read interrupted
Starting remote logger. Port: 59865
After accept
Background concurrent copying GC freed 105854(5142KB) AllocSpace objects, 7(268KB) LOS objects, 79% free, 1600KB/7744KB, paused 2.517ms total 125.132ms
Reducing the number of considered missed Gc histogram windows from 168 to 100
Log reader error: java.io.InterruptedIOException: read interrupted
-1 received
writer error
java.lang.InterruptedException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2042)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2076)
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:387)
    at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:160)
    at java.lang.Thread.run(Thread.java:919)
Starting remote logger. Port: 59865
After accept
B4X:
 
Upvote 0

GeoT

Active Member
Licensed User
And it seems that capturing only the data of the applications that interest me and discarding saving the data from WhatsApp notifications, it always captures.
But it is only a hypothesis for the moment.
 
Upvote 0

GeoT

Active Member
Licensed User
Wow no

B4X:
** Activity (main) Pause, UserClosed = false **
MSG_WINDOW_FOCUS_CHANGED 0 1
prepareNavigationBarInfo() DecorView@d3761c1[main]
getNavigationBarColor() -855310
Input channel destroyed: 'ClientS', fd=72
eglDestroySurface() in
delete_surface() [1080x2340] return
eglDestroySurface() out
EGLNativeWindowType 0x70e03f2e50 disconnect failed
Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)8 dur=6 res=0x5 s={false 0} ch=true
stopped(true) old=false
eglDestroySurface() in
delete_surface() [513x116] return
eglDestroySurface() out
EGLNativeWindowType 0x704f619790 disconnect failed
dispatchDetachedFromWindow
Input channel destroyed: 'c985db8', fd=81
-1 received
Log reader error: java.io.InterruptedIOException: read interrupted
writer error
java.lang.InterruptedException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2042)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2076)
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:387)
    at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:160)
    at java.lang.Thread.run(Thread.java:919)
java.io.IOException: shutdown failed: ENOTCONN (Transport endpoint is not connected)
    at java.net.PlainSocketImpl.socketShutdown(PlainSocketImpl.java:283)
    at java.net.AbstractPlainSocketImpl.shutdownInput(AbstractPlainSocketImpl.java:622)
    at java.net.Socket.shutdownInput(Socket.java:1570)
    at anywheresoftware.b4a.remotelogger.Connector.mainLoop(Connector.java:105)
    at anywheresoftware.b4a.remotelogger.Connector.run(Connector.java:53)
    at java.lang.Thread.run(Thread.java:919)
Caused by: android.system.ErrnoException: shutdown failed: ENOTCONN (Transport endpoint is not connected)
    at libcore.io.Linux.shutdown(Native Method)
    at libcore.io.ForwardingOs.shutdown(ForwardingOs.java:216)
    at libcore.io.ForwardingOs.shutdown(ForwardingOs.java:216)
    at java.net.PlainSocketImpl.socketShutdown(PlainSocketImpl.java:281)
    ... 5 more
Starting remote logger. Port: 59865
After accept
 
Upvote 0

DonManfred

Expert
Licensed User
Where is the Relevant code you are using?
Does it work in Release mode?
 
Upvote 0

GeoT

Active Member
Licensed User
The relevant code I'm using is in this method in the NotificationService
B4X:
Listener_NotificationPosted (SBN As StatusBarNotification)

And yes, it works in launch mode.

I added to save the smallicon from NotificationListener get small icon

I keep filtering the package name to save the data in files, and now I save the smallicon if it does not exist and if it is from the desired package.

At the moment it seems that it works by filtering more. Well, maybe it made him write too much before.

But before, especially when starting the smartphone, it did not capture the notifications automatically, but I had to use the GetActive method.

I have yet to do more tests. Thank you.
 
Upvote 0

GeoT

Active Member
Licensed User
The problem is that it fails to capture notifications when it is not being emulated connected to B4A Bridge. :(
 
Upvote 0

GeoT

Active Member
Licensed User
With the version 2 of the NotificationListener library:

It does nothing.
The unfiltered logger only says:
B4X:
onNotificationPosted

For each notification

The system says it runs a service in Developer Options / Running Services

-----

With the version 1.20 of the NotificationListener library:

Sometimes I save the notification data to files, as I want.

The unfiltered logger says:
B4X:
text = abcde
Success
** Service (notificationservice) Start **
NotificationPosted, package = b4a.notificationlistener, id = 2147483647, tikertext =
(Bundle) Bundle [{android.reduced.images = true, android.appInfo = ApplicationInfo {99c0503 b4a.notificationlistener}}]
Title = null
text = null
Log reader error: java.io.InterruptedIOException: read interrupted
-1 received
writer error
java.net.SocketException: Socket closed
at java.net.SocketOutputStream.socketWrite (SocketOutputStream.java:124)
at java.net.SocketOutputStream.write (SocketOutputStream.java:149)
at anywheresoftware.b4a.remotelogger.Connector $ Writer.run (Connector.java:161)
at java.lang.Thread.run (Thread.java:919)
Starting remote logger. Port: 59865
After accept
Log reader error: java.io.InterruptedIOException: read interrupted
-1 received
writer error
java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.reportInterruptAfterWait (AbstractQueuedSynchronizer.java:2042)
at java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await (AbstractQueuedSynchronizer.java:2076)
at java.util.concurrent.ArrayBlockingQueue.take (ArrayBlockingQueue.java:387)
at anywheresoftware.b4a.remotelogger.Connector $ Writer.run (Connector.java:160)
at java.lang.Thread.run (Thread.java:919)
Starting remote logger. Port: 59865
After accept
prepareNavigationBarInfo () DecorView @ 37e11fb [main]
getNavigationBarColor () -855310
Starting input: tba = b4a.notificationlistener ic = null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true, NavVisible: true, NavTrans: false
startInputInner - Id: 0
startInputInner - mService.startInputOrWindowGainedFocus
Input channel destroyed: 'ClientS', fd = 69
** Activity (main) Pause, UserClosed = false **
stopped (true) old = false
MSG_WINDOW_FOCUS_CHANGED 0 1
prepareNavigationBarInfo () DecorView @ 37e11fb [main]
getNavigationBarColor () -855310
** Service (notificationservice) Start **
NotificationPosted, package = com.google.android.googlequicksearchbox, id = -1873494995, tikertext =


The system says it runs two services in Developer Options / Running Services, which crash and restart, or the system says it gives problems
 
Last edited:
Upvote 0

GeoT

Active Member
Licensed User
Now the app works fine for me with version 1.2 of the NotificationListener library.
It is seen that some icon that received was android.graphics.drawable.VectorDrawable.

But until recently, Android told me that my app used a lot of battery. But not anymore.
Also curiously, Android tells me that I have two services active, I don't know why.
 
Last edited:
Upvote 0

GeoT

Active Member
Licensed User
It seems that now it works with version 1.2 of the library.

The main problems were that getting the small icon does not always get a BitmapDrawable and that the Listener_NotificationPosted event did not know in which folder to save the files, if the application activity was not started, it seems to me.

Solved by putting a Try and Catch on getting the icon and moving RuntimePermission object to service and putting in the Listener_NotificationPosted event

B4X:
If FilesFolder = "" Then FilesFolder = Rp.GetSafeDirDefaultExternal("NotificationListenerFiles")
 
Upvote 0
Top