Previusly我使用PhoneSms.send方法发送一条消息,一切都很好,现在我有以下Sub发送多部分消息:
Sub SendLargeSms(Destination As String, Message As String)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim smsManager As JavaObject
smsManager = smsManager.InitializeStatic("android.telephony.SmsManager").RunMethod("getDefault", Null)
Dim parts As Object = smsManager.RunMethod("divideMessage", Array(Message))
Dim i As Intent
i.Initialize("b4a.smssent", "")
Dim pi As JavaObject
pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
Array(ctxt, 0, i, 134217728))
Dim al As JavaObject
al.InitializeNewInstance("java.util.ArrayList", Null)
al.RunMethod("add", Array(pi))
smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, Null))
End Sub
我正在使用以下方法来捕获短信状态:
Sub check_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
If Success=False Then
Starter.sql.ExecNonQuery2( "update report set `message`=?,`status`=?,`date`=?
where mobile=? and send_code=?" , Array As
Object(ErrorMessage,"-1",DateTime.Date(DateTime.Now),PhoneNumber,send_code) )
Else
Starter.sql.ExecNonQuery2( "update report set `message`=?,`status`=?,`date`=?
where mobile=? and send_code=?" , Array As
Object("Sent","1",DateTime.Date(DateTime.Now),PhoneNumber,send_code) )
End If
End Sub
问题是我得到的PhoneNumber总是为空,我不知道如何确定哪个号码收到了该消息。 这发生在我使用SendLargeSms而不是PhoneSms对象的send方法之后。我找不到问题,因为似乎SendLargeSms代码正在使用Java Methods.Thank You
答案 0 :(得分:0)
我自己解决了,谢谢
Sub SendLargeSms(Destination As String, Message As String , send_code As String)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim smsManager As JavaObject
smsManager = smsManager.InitializeStatic("android.telephony.SmsManager").RunMethod("getDefault", Null)
Dim parts As Object = smsManager.RunMethod("divideMessage", Array(Message))
Dim i As Intent
i.Initialize("b4a.smssent", "")
i.PutExtra("mobile",Destination)
i.PutExtra("send_code",send_code)
Dim pi As JavaObject
pi = pi.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
Array(ctxt, 0, i, 134217728))
'Adding sms deliver
Dim i2 As Intent
i2.Initialize("b4a.smsdelivered", "")
i2.PutExtra("mobile",Destination)
i2.PutExtra("send_code",send_code)
Dim pi2 As JavaObject
pi2 = pi2.InitializeStatic("android.app.PendingIntent").RunMethod("getBroadcast", _
Array(ctxt, 0, i2, 134217728))
Dim al As JavaObject
al.InitializeNewInstance("java.util.ArrayList", Null)
al.RunMethod("add", Array(pi))
al.RunMethod("add", Array(pi2))
smsManager.RunMethod("sendMultipartTextMessage", Array(Destination, Null, parts, al, Null))
End Sub