Bug? NotificationListener Stops catching notifications

Gentry

Member
Licensed User
Longtime User
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.

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

Thanks for looking.
Gentry
 

Gentry

Member
Licensed User
Longtime User
I havent been able to catch the failed state when connected to adb. So, no logs.

Isnt the special internal notification listener service a b4a base feature (not part of the library)? If so, it felt more like a big that its crashing and not restarting.

Just asking for a workaround.

At least its a new thread
 

Gentry

Member
Licensed User
Longtime User
Ok I reposted in questions.this forum software needs a way to change the forum from more than one level deep(bug or wish the only edit option). Or a way to delete bad threads. Sorry for offending.
 
Top