#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
Private listener As NotificationListener
End Sub
Sub Service_Create
listener.Initialize("listener")
End Sub
Sub Service_Start (StartingIntent As Intent)
If listener.HandleIntent(StartingIntent) Then Return
End Sub
Sub Listener_NotificationPosted (SBN As StatusBarNotification)
Dim p As Phone
If p.SdkVersion >= 19 Then
Dim jno As JavaObject = SBN.Notification
Dim extras As JavaObject = jno.GetField("extras")
extras.RunMethod("size", Null)
If SBN.PackageName.Contains("whatsapp") Then
Dim title As String = extras.RunMethod("getString", Array As Object("android.title"))
LogColor("Name = " & title, Colors.Blue)
ToastMessageShow("Name: " & title,False)
Dim cu As Contacts
For Each c As Contact In cu.FindByName(title,True)
Dim loc_Phones As Map
loc_Phones.Initialize
loc_Phones = c.GetPhones
Dim loc_NumberFrom As String = ""
Dim x As Int=0
For x=0 To loc_Phones.Size-1
If loc_Phones.GetValueAt(x) = c.PHONE_MOBILE Then
loc_NumberFrom = loc_Phones.GetKeyAt(x)
loc_NumberFrom = loc_NumberFrom.Replace(" ","")
loc_NumberFrom = loc_NumberFrom.Replace("-","")
LogColor("Number = " & loc_NumberFrom, Colors.Blue)
ToastMessageShow("Number: " & loc_NumberFrom, False)
End If
Next
Next
Dim text As String = extras.RunMethod("getString", Array As Object("android.text"))
'LogColor("text = " & text, Colors.Blue)
Dim loc_message As String = text
If text = "null" Then
Try
Dim lines() As Object = extras.RunMethod("getCharSequenceArray", Array("android.textLines"))
For Each line As Object In lines
'Log(line)
loc_message = line
Next
Catch
LogColor("Error!" & title, Colors.Red)
End Try
End If
LogColor("Message = " & loc_message, Colors.Blue)
ToastMessageShow("Message: " & loc_message, False)
'Cancella Notifiche
'listener.ClearNotification(SBN)
Else
'Per posta o altro
'ToastMessageShow("NotificationPosted, package = " & SBN.PackageName & ", id = " & SBN.Id & _
'", text = " & SBN.TickerText, False)
Dim p As Phone
Dim jno As JavaObject = SBN.Notification
Dim extras As JavaObject = jno.GetField("extras")
extras.RunMethod("size", Null)
Log(extras)
Dim title As String = extras.RunMethod("getString", Array As Object("android.title"))
Dim text As String = extras.RunMethod("getString", Array As Object("android.text"))
LogColor("Title = " & title, Colors.Blue)
If title <> "null" Then
ToastMessageShow(title, True) 'title
End If
If text <> "null" Then
ToastMessageShow(text, True) 'testo
End If
End If
End If
End Sub
Sub Listener_NotificationRemoved (SBN As StatusBarNotification)
Log("NotificationRemoved, package = " & SBN.PackageName & ", id = " & SBN.Id & _
", text = " & SBN.TickerText)
End Sub
Sub ClearAll
listener.ClearAll
End Sub
Sub GetActive
listener.GetActiveNotifications
End Sub
Sub Service_Destroy
End Sub