1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Sent SMS messages won't appear in the log

Discussion in 'Android Questions' started by NeoTechni, Nov 3, 2012.

  1. NeoTechni

    NeoTechni Well-Known Member Licensed User

    I'm using

    Code:
    Sub SendTextMessage(PhoneNumber As String, Message As String)As Boolean 
       
    Dim SmsManager As PhoneSms ,r As Reflector, parts As Object
       
    If PhoneNumber.Length>0 Then
          
    Try
             
    If Message.Length <= 160 Then 
                SmsManager.Send(PhoneNumber, Message)
             
    Else
                 r.Target = r.RunStaticMethod(
    "android.telephony.SmsManager""getDefault"NullNull)
                 parts = r.RunMethod2(
    "divideMessage", Message, "java.lang.String")
                r.RunMethod4(
    "sendMultipartTextMessage"Array As Object(PhoneNumber, Null, parts, NullNull), Array As String("java.lang.String""java.lang.String""java.util.ArrayList""java.util.ArrayList""java.util.ArrayList"))
             
    End If
             
    Return True
          
    Catch
          
    End Try
       
    End If
    End Sub
    to send SMS messages, but they don't appear in the history. Do I have to store them myself (which people won't like due to privacy concerns)?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you checking it with SmsMessages object?
     
  3. NeoTechni

    NeoTechni Well-Known Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    You will need to manually add it to the logs with this code:

    Code:
    Sub AddMessageToLogs(body As Stringaddress As String)
       
    Dim r As Reflector
       r.Target = r.CreateObject(
    "android.content.ContentValues")
       r.RunMethod3(
    "put""address""java.lang.String"address"java.lang.String")
       r.RunMethod3(
    "put""body""java.lang.String", body, "java.lang.String")
       
    Dim contentValues As Object = r.Target
       r.Target = r.GetContext
       r.Target = r.RunMethod(
    "getContentResolver")
       r.RunMethod4(
    "insert"Array As Object( _
          r.RunStaticMethod(
    "android.net.Uri""parse"Array As Object("content://sms/sent"), _
             
    Array As String("java.lang.String")), _
          
    contentValues), Array As String("android.net.Uri""android.content.ContentValues"))
    End Sub
    You should also add the following permissions:
    Code:
    AddPermission(android.permission.WRITE_SMS)
    AddPermission(android.permission.READ_SMS)
     
    pesquera likes this.
  5. NeoTechni

    NeoTechni Well-Known Member Licensed User

    Thank you.

    Questions:

    For messages longer than 160 characters, I split it up into an array (parts), do I have to add each cell/part of that individually or can I just add the big/total message?

    For MMS messages (with a picture) how do I add the picture to the log?

    How do I set the status of the message? Ie: Sent, failed to send, draft?

    Also, how can I mark an SMS thread as read?
     
    Last edited: Nov 4, 2012
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that you need to split the message.

    How do you send MMS messages?

    Google for "content://sms" you will see the available fields.
     
  7. jalle007

    jalle007 Active Member Licensed User



    This one is working like a charm. THX Erel
     
    Mark Zraik likes this.
  8. hookshy

    hookshy Well-Known Member Licensed User

    thanks guys i works great
     
  9. mangojack

    mangojack Well-Known Member Licensed User

    just to save searching (took me a while)... see Erels code Post #4 - manually write 'Sent' SMS to Logs.

    A line change is required to manually write 'Received' SMS to logs ..
    Code:
    Sub AddMessageToLogs(From As String, Body As String)
         
    Dim r As Reflector
         r.Target = r.CreateObject(
    "android.content.ContentValues")
         r.RunMethod3(
    "put""address""java.lang.String", From, "java.lang.String")
         r.RunMethod3(
    "put""body""java.lang.String", Body, "java.lang.String")
         
    Dim ContentValues As Object = r.Target
         r.Target = r.GetContext
         r.Target = r.RunMethod(
    "getContentResolver")
         r.RunMethod4(
    "insert"Array As Object( _
      r.RunStaticMethod(
    "android.net.Uri""parse"Array As Object("content://sms/inbox"), _  '  @@ !!  ....  ("content://sms/sent")  to write sent SMS to Logs
      Array As String("java.lang.String")),ContentValues), Array As String("android.net.Uri""android.content.ContentValues"))
        
    End Sub
     
  10. Mark Zraik

    Mark Zraik Member Licensed User

    Thank you for your hard work, this was the missing step I needed.

    Coroner
     
  11. pesquera

    pesquera Active Member Licensed User

    Hi, this routine was so useful for me! thanks to all you guys (speccially Erel) to help new users like me
    I call this routine after another routine (SentLargeSms) and also after PhoneSMS.Send
    But, sometimes the order of the log is wrong (I can see first the sms send and later the sms received on Handcent)
    How can I do to that? I've tried with this without luck:
    Code:
    CallSubDelayed3(Me,"SendLargeSms",ContactNumber,Text)
    SendLargeSms(ContactNumber,Text)
    miPhoneSMS.Send(ContactNumber,Text)
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    I'm not sure that I exactly understand your code. However CallSubDelayed sends a message to the message queue. Only when the message is processed will the sub be called. So it will only happen after the two other subs.
     
    pesquera likes this.
  13. pesquera

    pesquera Active Member Licensed User

    don't worry about the code Erel, it was for testing purpose.. your explanation helped to me with this.. thanks again!
     
  14. lazreg

    lazreg Active Member Licensed User

    Hi guys,,,,,
    How To Remove SMS log from Call log?
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question (also please use the default text).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice