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

bgsoft

Well-Known Member
Licensed 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
thanks Erel
 

bgsoft

Well-Known Member
Licensed 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
 

bgsoft

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

Uitenhage

Member
Licensed 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
 

koaunglay

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

koaunglay

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

lemonisdead

Well-Known Member
Licensed 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
 

koaunglay

Member
Licensed 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!
 

Joy Garcia

Member
Licensed 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
 
Top