简体   繁体   中英

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:

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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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