B4A Library WhatsApp Library

WhatsApp Library
Version: 1.1

This is a wrapper for this Github-project.


2015-03-07 22.12.56.png




WhatsApp
Author:
Devil-App
Version: 1.1
  • Whatsapp
    Fields:
    • AUDIO_TYPE As Int
    • IMAGE_TYPE As Int
    • VIDEO_TYPE As Int
    Methods:
    • OpenChatWithNumber (phoneNumber As String)
      Open Chat with Number
      Example:<code>
      Dim whapp As WhatsApp
      whapp.OpenChatWithNumber("+39334336444")</code>
    • createPhoneNumber (displayName As String, mobileNumber As String, email As String)
      This method create a contact.
      Example:<code>
      Dim whapp As WhatsApp
      whapp.createPhoneNumber("Devil","+393343365647","info@devil-app.com"</code>
    • existPhoneNumber (phoneNumber As String) As Boolean
      This method determines if a mobileNumber is a contact.
      Example:<code>
      Dim whapp As WhatsApp
      if whapp.existPhoneNumber("+393343365647") then MsgBox("Ok","msg")</code>
    • isInstalled As Boolean
      This method determines if Whatssap are installed.
      Example:<code>
      Dim whapp As WhatsApp
      if whapp.isInstalled then MsgBox("Installed","Msg")</code>
    • launchMarket
      This method go to Market.
      Example:<code>
      Dim whapp As WhatsApp
      whapp.launchMarket</code>
    • shareMediaWithContact (uri As Uri, mediaType As Int)
      Share Media with Contact
      Example:<code>
      Example: shareMediaWithContact(Activity.this, uriMedia, IMAGE_TYPE);
      Example: shareMediaWithContact(Activity.this, uriMedia, AUDIO_TYPE);
      Example: shareMediaWithContact(Activity.this, uriMedia, VIDEO_TYPE);
      Dim whapp As WhatsApp
      whapp.shareMediaWithContact(uriMedia, whapp.VIDEO_TYPE)</code>
    • shareTextWithContact (text As String)
      Share Text with Contact
      Example:<code>
      Dim whapp As WhatsApp
      whapp.shareTextWithContact("Hi...how are you")</code>
    Permissions:
    • android.permission.READ_CONTACTS
    • android.permission.SEND_SMS
    • android.permission.WRITE_CONTACTS

Example ( with mp4, mp3 example 3.7 Mb ) and so you can download here: Devil-App
Library in attachment
LAST REL 1.1
Bye
Marco
 

Attachments

  • WhatsApp-Library.zip
    4.2 KB · Views: 1,683
  • WhatsApp-Lib1.1.zip
    4.3 KB · Views: 2,033
  • Whatsapp-Source.zip
    6.8 KB · Views: 1,818
Last edited:

luiswagnersantos

Member
Licensed User
Great. Good Work. Congratulations! Fantastic!
 

Ricardo Bunschoten

Active Member
Licensed User
If i use the function
  • OpenChatWithNumber (phoneNumber As String)
    Open Chat with Number
    Example:<code>
    Dim whapp As WhatsApp
    whapp.OpenChatWithNumber("+39334336444")</code>
And i dont have the contact in my adres list then whatsapp is giving me this message
Screenshot_2017-02-01-09-30-58.png


How to bypass this message ? without adding te contact to your adresbook ?
 

MarcoRome

Expert
Licensed User
If i use the function
  • OpenChatWithNumber (phoneNumber As String)
    Open Chat with Number
    Example:<code>
    Dim whapp As WhatsApp
    whapp.OpenChatWithNumber("+39334336444")</code>
And i dont have the contact in my adres list then whatsapp is giving me this message View attachment 52503

How to bypass this message ? without adding te contact to your adresbook ?
If it is not in your contact ISTN registered in Whatsapp. So is necessary
 
  • Like
Reactions: GIS

pesquera

Active Member
Licensed 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
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
 
Top