Android Question Add a message so native message app can see it

Similar threads

B4A Code Snippet Scrollbar Color
B4A Tutorial Custom transitions between activities
B4A Code Snippet Get CRC32 from File
B4A Question Sent SMS messages won't appear in the log
B4A Code Snippet Modify Headers in WebView

JackKirk

Well-Known Member
Licensed User
In this post:
https://www.b4x.com/android/forum/threads/log-or-write-sms-message-send-to-phone.10287/#post-102749

Erel shows code to "add a message to the phone logs" and the thread is in the vein of adding messages so the native message app can see them.

I've put this in a little test app but I can't get any obvious result when I run it - no errors either.

Am I fundamentally missing the point? where should the messages appear?

Also the post is circa 2012 so is the code still relevant?

I attach the body of Erel's post below for ease of reference:

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")
Any help or pointers appreciated...
 

DonManfred

Expert
Licensed User

JackKirk

Well-Known Member
Licensed User
DonManfred,
Are you using Runtimepermissions to request WRITE to the callog?
Yes I think, as per Erels original post
Probably Android does not allow this anymore (at higher Android Versions/SDK target)
I already have an app that commandeers SMS messages that runs on a standalone Android phone for a particular purpose.

When I was researching that I got the impression that you could still do anything you like with SMS just so long as you don't try to publish it.

If I can get this running it would also be for my private use.

But how...
 
Last edited:

JackKirk

Well-Known Member
Licensed User
Erel,
Try to make you app the default messaging app
I took your code as outlined in post #1 and put it in my app that commandeers SMS messages, as I mentioned in post #3.

When I install this merged app on my Samsung 5 and make it the default messaging app - it works - I get a message in the Messages queue.

This however is counter to what I want to do.

I want to have the native messaging app the default and have a separate app that (probably) messages via polling an AWS S3 bucket.

When the second app has a message I want to dump it in the Messages queue, accessible by the native messaging app.

I have a reason for wanting to do this - it is not an idle whim:):):)
 

JackKirk

Well-Known Member
Licensed User
Only the default messaging app can write to the SMS store.
It would appear so - drat!!!

On to plan B - save and view second app messages separately.
 

JackKirk

Well-Known Member
Licensed User
or you make a new SMS app that handles both...
I have looked at that - not a trivial task.

By any chance, would you know of any publicly available B4A code that I could use as a springboard?
 
Top