ciao a tutti, sto utilizzando il codice di esempio di whastapp acc services realizzato da moster, in questo esempio puoi inviare in modo automatico senza premere il pulsante invio un messaggio di testo ad un numero prestabilito, avrei la necessità di inviare anche una immagine insieme al testo, qualcuno sa dirmi come fare? allego codice completo:
ovviamente c'è anche un modulo di servizio che non ho allegato perchè credo che vada aggiunto qualcosa solo nel modulo main.
ovviamente c'è anche un modulo di servizio che non ho allegato perchè credo che vada aggiunto qualcosa solo nel modulo main.
B4X:
#Region Project Attributes
#ApplicationLabel: WhatsAppAccService
#VersionCode: 2
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
'adding additional resources. Modify below attribute to make it point to your location.
#AdditionalRes: C:\test1\resAccessibility\res, com.tillekesoft.accessibilityservices
'In above resource folder, there are two files to change according to your needs. For this example,
'it would be a good idea to tell the Accessibility Service to monitor only the whatsApp package...
'Check also the manifest in which you need to add some lines....
'for this example, you need to fill in phone numbers and group links. Of course, in a real
'app you would let the user do that....
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private lblDesc As Label
Private btnAccessibility As Button
Private CheckBox1 As CheckBox
Private btnAction As Button
Private txtMsg As EditText
Private btnSend As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
StartService(AccService)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnAccessibility_Click
CallSub(AccService,"CheckIfServiceIsEnabled")
End Sub
Sub SetCheckbox(Checked As Boolean)
If Checked Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
End Sub
Sub IsTheAccessibilityServiceEnabled (Status As Boolean)
If Status = False Then
Dim Intent1 As Intent
Intent1.Initialize( "android.settings.ACCESSIBILITY_SETTINGS", "" )
StartActivity( Intent1 )
Else
ToastMessageShow("Service is already enabled/running",True)
Return
End If
End Sub
Sub btnAction_Click
If txtMsg.Text.Length > 0 Then
Dim link As String = "xxxxxxxxxxxxxxxxxxxxxx" 'insert group link. Can only be seen in WhatsApp by user who created the group
Dim Url As String = "https://chat.whatsapp.com/" & link
Dim Intent1 As Intent
Dim pm As PackageManager
Intent1 = pm.GetApplicationIntent("com.whatsapp")
If Intent1.IsInitialized Then
'Se WhatsApp è installato
Dim Intent2 As Intent
Intent2.Initialize(Intent2.ACTION_VIEW, Url)
StartActivity(Intent2)
Else
ToastMessageShow("WhatsApp is not installed", True)
Return
End If
CallSub2(AccService, "SendWhatsAppMsgToGroup", txtMsg.Text.Trim)
End If
End Sub
Sub btnSend_Click
If txtMsg.Text.Length > 0 Then
Dim number As String = "+39123456789" 'here goes the phone number of the contact
number = number.Replace("+","").Replace(" ","")
Dim messaggio As String = txtMsg.Text.trim
Dim numero As String = number
Dim Intent1 As Intent
Dim pm As PackageManager
Intent1 = pm.GetApplicationIntent("com.whatsapp")
If Intent1.IsInitialized Then
'If WhatsApp is installed..
Dim Intent2 As Intent
Intent2.Initialize(Intent2.ACTION_VIEW, $"https://wa.me/${numero}?text=${messaggio}"$)
StartActivity(Intent2)
Else
ToastMessageShow("WhatsApp is not installed", True)
Return
End If
End If
CallSub(AccService,"SendWhatsAppMsg")
End Sub