简体   繁体   English

SmsSentStatus 方法接收 null 而不是 PhoneNumber

[英]SmsSentStatus method receives null instead of PhoneNumber

Previusly I was using PhoneSms.send method for sending one part message , and everything was fine,Now I got the following Sub for sending multpart message:以前我使用 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

I'm using the following method to capture sms status :我正在使用以下方法来捕获短信状态:

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

The problem is the PhoneNumber I got is always null and I don't know how to determine which number has received the message.问题是我得到的 PhoneNumber 总是空的,我不知道如何确定哪个号码收到了消息。 This happened just after I used SendLargeSms instead of the send method of PhoneSms object.I could't find the problem because it seems SendLargeSms code is using Java methods.Thank You这发生在我使用 SendLargeSms 而不是 PhoneSms 对象的 send 方法之后。我找不到问题,因为 SendLargeSms 代码似乎使用的是 Java 方法。谢谢

I solved it myself ,Thank you我自己解决了,谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM