I am using the following code to send a text message. It works without any issues. However, I do get a warning telling me that the variable ps is never assigned a value. If I comment out the line: DIM ps As PhoneSms, the code no longer works.
I was wondering if someone could explain why it works if it is never assigned any value?
I was wondering if someone could explain why it works if it is never assigned any value?
B4X:
Sub SendSms(PhoneNumber As String, Text As String)
Try
Dim ps As PhoneSms
Dim r As Reflector
r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
r.RunMethod4("sendTextMessage", Array As Object(PhoneNumber, Null, Text, Null, Null), _
Array As String("java.lang.String", "java.lang.String", "java.lang.String", _
"android.app.PendingIntent", "android.app.PendingIntent"))
ToastMessageShow("Text was sent to " & PhoneNumber & ".",False)
Catch
ToastMessageShow("The text was not sent to " & PhoneNumber & ".",False)
End Try
End Sub