My current project relies on catching notifications, and frequently stops catching notifications. I discovered that to restore the functionality, I need to disable then re-enable Notification Access in the system control panel, which seems to reset the "hook" and then new notifications are captured as expected.
I haven't figured out how to cause the listener to 'break' and haven't been able to catch the failure while connected to logging. But it happens so frequently I needed to add a test feature for the user to check if it is functioning (A button creates a notification and if the app doesn't capture it, then it leads the user to re-set Notification Access).
I suspect that the Notification Internal Service is crashing, failure seems to occur when a notification that is not even being processed by the app is received by the device, and is not restarting on it's own.
Is there a way to detect the running state and force a reset of the Notification Internal Service so I don't need to bother my users to do it manually?
Here is my Listener_NotificationPosted code, but it works fine, until something "un-hooks" the listener.
Edit: reposting in the correct forum, I hope. Guess its not a "bug".
Thanks for looking.
Gentry
I haven't figured out how to cause the listener to 'break' and haven't been able to catch the failure while connected to logging. But it happens so frequently I needed to add a test feature for the user to check if it is functioning (A button creates a notification and if the app doesn't capture it, then it leads the user to re-set Notification Access).
I suspect that the Notification Internal Service is crashing, failure seems to occur when a notification that is not even being processed by the app is received by the device, and is not restarting on it's own.
Is there a way to detect the running state and force a reset of the Notification Internal Service so I don't need to bother my users to do it manually?
Here is my Listener_NotificationPosted code, but it works fine, until something "un-hooks" the listener.
B4X:
Sub Listener_NotificationPosted (SBN As StatusBarNotification)
Dim temptitle As String
If Starter.MyLocation.IsInitialized = False Then
StartService(loc)
Else If Starter.MyLocation.Latitude = 0 Then
StartService(loc)
End If
NameGuesses = ""
GeoFenceUp=False
FenceFlag = False
If Starter.MyLocation.Latitude = 0 Then
StartService(loc)
End If
Dim p As Phone
Dim text As String
Dim LastAlertLocFile As RandomAccessFile
Dim LastAlertLoc As String
If p.SdkVersion >= 19 Then
DateTime.DateFormat = "yyyyMMdd"
lasttimestamp = DateTime.Now
Dim jno As JavaObject = SBN.Notification
Dim extras As JavaObject = jno.GetField("extras")
extrastring = extras
extras.RunMethod("size", Null)
temptitle = extras.RunMethod("getString", Array As Object("android.title"))
If SBN.PackageName = "com.capture.app" Then
title = temptitle
End If
If Main.testflag And SBN.PackageName = "com.b4aexample" Then
ToastMessageShow("Notification Captured",False)
If isMessageTest Then
isMessageTest = False
Dim nb As NotificationBuilder
nb.Initialize
nb.Cancel(300)
ToastMessageShow("Capture Working, All Good!", True)
If Main.EventList.IsInitialized Then
Main.EventFile.WriteB4XObject(Main.EventList,0)
Main.EventFile.flush
End If
Else
title = extras.RunMethod("getString", Array As Object("android.title"))
address = extras.RunMethod("getString", Array As Object("android.text"))
currentLoc.Initialize(address,Me,"New_Event")
End If
Main.testflag = False
End If
If SBN.PackageName = "com.capture.app" Then
u.tlog2("L_NP "&SBN.PackageName & " " & extrastring,5)
title = extras.RunMethod("getString", Array As Object("android.title"))
address = extras.RunMethod("getString", Array As Object("android.text"))
currentLoc.Initialize(address,Me,"New_Event")
End If
End If
End Sub
Edit: reposting in the correct forum, I hope. Guess its not a "bug".
Thanks for looking.
Gentry