Android Question Send SMS without appearing in "sent messages" of the device

bgsoft

Well-Known Member
Licensed User
Longtime User
If sending SMS to any of these two systems:

B4X:
'1)
  Dim ps As PhoneSms
  Dim r As Reflector
  r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
  r.RunMethod4("sendTextMessage", Array As Object("phone number", Null, "Hello", Null, Null), _
  Array As String("java.lang.String", "java.lang.String", "java.lang.String","android.app.PendingIntent", "android.app.PendingIntent"))

'-------------------------------------------------------------------------------------------------

'2)
Dim Sms1 As PhoneSms
Sms1.Send(phone number,"hello")


The message appears in "sent messages" of the device
As I can send an SMS, without appearing in "sent messages" of the device?

thanks
 

bgsoft

Well-Known Member
Licensed User
Longtime User
thanks Erel
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi Erel

Forgive my ignorance. I have looked all phone library. And I not find anything to delete from the list of device sent an SMS.

Please, you can put a line of code on how to do?

thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Dim cr As ContentResolver
cr.Initialize("cr")
Dim u As Uri
u.Parse("content://sms")
Log(cr.Delete(u, "_id = ?", Array As String(<id>))) 'should print 1
Note that starting from Android 4.4 only the default SMS app can delete messages.

You need to add this permission:
B4X:
 AddPermission(android.permission.WRITE_SMS)
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Thank you so much for your quick response and example
 
Upvote 0

Uitenhage

Member
Licensed User
Longtime User
Erel,

Note that starting from Android 4.4 only the default SMS app can delete messages.

So this code won't prevent the message from appearing in the Message app on Android 4.4 and higher?
B4X:
Sub Service_Create   
    Dim SI As SmsInterceptor
    SI.Initialize2("SI", 999)
End Sub
Sub SI_MessageReceived (SMSSender As String, SMSBody As String) As Boolean 
    Dim ReturnValue As Boolean
    If SMSBody.ToLowerCase.StartsWith("TrapThisOne(") Then        'Filter for our messages here
        SMS_Sender = SMSSender        'Store in Globals for responding routines to use
        SMS_Body = SMSBody            'Store in Globals for responding routines to use
        Select Case SMS_Body
            Case "TrapThisOne(1)"
                'do Process 1
            Case "TrapThisOne(2)"
                'do Process 1
        End Select
        Log(ModuleName & ".SI_MessageReceived: Ours" & SMSSender & ":[" & SMSBody & "]")
        ReturnValue = True        'tell OS that we've handled this one
    Else
        Log(ModuleName & ".SI_MessageReceived: Not Ours:" & SMSSender & ":[" & SMSBody & "]") 
        ReturnValue = False        'Not one of ours- let the default handler take this message
    End If
    Return ReturnValue
End Sub

Will the delete solution (post #5) get both sent and received messages?

Thanks,

Jim
 
Upvote 0

koaunglay

Member
Licensed User
Longtime User
When I install some apk, I received sms message by apk name. There isn't sender phone number. How should it makes like that? My English is not good.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
My English is not good
OK but what do you mean ?

There isn't sender phone number.
Do you mean you don't find a phone number to send the message to ? If yes, you have to provide the number yourself.
Or do you mean : some apps don't find your own phone number ?

Thanks
 
Upvote 0

koaunglay

Member
Licensed User
Longtime User
I mean I can't find phone number. Examples when I install hello.apk. I received sms from hello. Phone number is hello. Message is Thank U.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Check if you don't have a Hello account in the Android's settings. If yes, you can be sure they use a separated db for their contact information.
You can do the same by using ContactsUtils for example and by adding your sender's number to the contacts with the name you want
 
Upvote 0

koaunglay

Member
Licensed User
Longtime User
Thanks a lot friend for your reply. But when I get message I didn't find in my contact. I mean there's no name hello in my contact. Thanks anyway!
 
Upvote 0

JhoeyBoy

Member
Licensed User
Longtime User
how to fix this problem?



** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (lancer) Create **
** Service (lancer) Start **
ConnectivityChanged: WIFI, state = CONNECTED
Bundle[{networkInfo=[type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "GLOBE_0219", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false], networkType=1, inetCondition=0, extraInfo="GLOBE_0219"}]
BatteryChanged: Level = 36, Scale = 100, Plugged = true
TextToSpeechFinish
BatteryChanged: Level = 36, Scale = 100, Plugged = true
BatteryChanged: Level = 36, Scale = 100, Plugged = true
BatteryChanged: Level = 36, Scale = 100, Plugged = true
BatteryChanged: Level = 36, Scale = 100, Plugged = true
** Activity (main) Pause, UserClosed = false **
BatteryChanged: Level = 36, Scale = 100, Plugged = true
MessageReceived: From = +639485124778, Body = Lancer

java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } in anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2@1a1429c4
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:919)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2.onReceive(PhoneEvents.java:398)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:909)
... 8 more
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top