#Region Project Attributes
#ApplicationLabel: SMS Texting
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#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.
Dim Permissions As List
Private EditTextPhoneNumber As EditText
Private EditTextText As EditText
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("main")
Permissions.Initialize
Permissions.Add(Starter.rp.PERMISSION_SEND_SMS)
Permissions.Add(Starter.rp.PERMISSION_RECEIVE_SMS)
Permissions.Add(Starter.rp.PERMISSION_READ_PHONE_STATE)
Permissions.Add(Starter.rp.PERMISSION_READ_CALL_LOG)
End Sub
Sub Activity_Resume
For Each permission As String In Permissions
If Starter.rp.Check(permission) = False Then
Sleep(200)
Starter.rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
Log(permission)
If Result = False Then
ToastMessageShow("No permission " & permission, True)
Starter.rp.CheckAndRequest(permission)
Sleep(200)
Return
End If
End If
Next
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SendLargeSms(Destination As String, Message As String, Extra As String)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim smsManager As JavaObject
smsManager = smsManager.InitializeStatic("android.telephony.SmsManager").RunMethod("getDefault", Null)
Dim parts As JavaObject = smsManager.RunMethod("divideMessage", Array As String (Message))
Dim size As Int = parts.RunMethod("size", Null)
Dim i As Intent
i.Initialize("b4a.smssent", "")
i.PutExtra("phone", Destination)
i.PutExtra("message_id", Extra)
Dim pi As JavaObject
pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
Array(ctxt, 0, i, 134217728))
Dim i2 As Intent
i2.Initialize("b4a.smsdelivered", "")
i2.PutExtra("phone", Destination)
i2.PutExtra("message_id", Extra)
Dim pi2 As JavaObject
pi2 = pi2.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
Array(ctxt, 0, i2, 134217728))
Dim al, al2 As JavaObject
al.InitializeNewInstance("java.util.ArrayList", Null)
al2.InitializeNewInstance("java.util.ArrayList", Null)
For ii = 0 To size - 2
al.RunMethod("add", Array(Null))
al2.RunMethod("add", Array(Null))
Next
al.RunMethod("add", Array(pi))
al2.RunMethod("add", Array(pi2))
smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, al2))
End Sub
Sub ButtonSendText_Click
SendLargeSms(EditTextPhoneNumber.Text, EditTextText.Text, "")
End Sub
Sub ButtonClose_Click
Dim i As Intent
i.Initialize(i.ACTION_MAIN, "")
i.AddCategory("android.intent.category.HOME")
i.Flags = 0x10000000
StartActivity(i)
End Sub