Log or write SMS message send to phone

metrick

Active Member
Licensed User
Longtime User
How can I update/save SMS message to phone Calllog after I have sent message?
I can send SMS message with phonesms, but I want to keep track of messages sent in phone call log just like texting.

Thanks in advance.
 

metrick

Active Member
Licensed User
Longtime User
Erel:
I don't know if my questions were clear.
I want to store the phonesms sent message in smsmessage on the phone.

dim phsms as phonesms
dim mytext as string
mytext = "My Message"

phsms.Send(555xxxyyyy,mytext)

'I would like to store mytext in smsmessage so user can see what message they have sent and keep track with date and time
 
Upvote 0

metrick

Active Member
Licensed User
Longtime User
Erel:
After the message is sent and I tried to retrieve message with followings code:

Dim SmsMessages1 As SmsMessages
Dim List1 As List
List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now, 0, 0, -1))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
Log(Sms)
Next

I did not see the message that I sent with the above codes, however the message was sent and received by Recipient phone number.
No there is no problem with sending message via phone build in messaging.
 
Upvote 0

metrick

Active Member
Licensed User
Longtime User
Your code looks correct. Try to send a message manually (not with code) and see if you get it with the above code.

Erel:
I have tried the message manually and able to view the message with the above codes.
However, when I send message with code is not saved.
 
Upvote 0

metrick

Active Member
Licensed User
Longtime User
That's is what I'm afraid of, trying to look for simple solution first.
Thanks, Erel. You're great help for me learning B4A.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
So, finally - sent by code messages - are not saved in system's "sent" store for sure at any Android version\device?
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
That is correct.
Is there any way we can save it to the phone's sent folder? There should be a way as even if we use, Handcent or any third party messaging client, the sent messages are stored in the phone's native sent folder.
how can we do this with B4A please?
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
I'm not familiar with such a folder. Where is it located?
Sorry Erel, I think I didn't clearly explain myself. I am talking about messaging application. When you send a text message to a recipient it gets saved. It doesn't matter which messaging application you use (like native messaging app, Handcent or Gosms) all of them can see the 'sent' and 'received' messages. If you send a message using Handcent app, you can see that message using Android Native Messaging client. Is there a way to save a sent message by using 'PhoneSms'.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to add a message to the phone logs:
B4X:
Sub AddSentSms(Address As String, Body As String)
   Dim r As Reflector
   Dim values As Object
   values = r.CreateObject("android.content.ContentValues")
   r.Target = values
   Dim s As String
   s = "java.lang.String"
   r.RunMethod4("put", Array As Object("type", 2), Array As String(s, "java.lang.Integer"))
   r.RunMethod3("put", "address", s, Address, s)
   r.RunMethod3("put", "body", s, Body, s)
   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(s)), values), _
      Array As String("android.net.Uri", "android.content.ContentValues"))
End Sub
This code requires reflection library.

You should add this manifest editor code:
B4X:
AddPermission("android.permission.WRITE_SMS")
AddPermission("android.permission.READ_SMS")
 
Upvote 0
Top