B4A Library WhatsApp Library

pesquera

Active Member
Licensed User
Longtime User
Hi Marco, thanks for this great library! very useful to me.. just a question: is there any way to close an opened chat?
 

MarcoRome

Expert
Licensed User
Longtime User
This is code in Service NotificationService to intercept Whatsapp:
B4X:
#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
 

Mirko Melegari

Member
Licensed User
Longtime User
Ho visto gli esempi per inviare messaggi con whatsapp , c'e' qualcuno che ha realizzato una procedura per inviare lo stesso messaggio o immagine, a una lista di contatti preparata da programma?
Grazie
 

amorosik

Expert
Licensed User
Using this library is it possible to read the existing chats, and subsequently the messages / media contained in a chat?
And then do the opposite, so from the messages / media read, upload them to a specific chat?
The use would be to carry out a backup / restore procedure from one phone to another
 

MarcoRome

Expert
Licensed User
Longtime User
No
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…