Android Question [SOLVED] Issues in delete a SMS

CanguroCode

Active Member
Licensed User
Longtime User
I need manage and delete some SMS (spam in general). I been reading the posts::

- https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/
- https://www.b4x.com/android/forum/t...sages-without-notification-android-4-4.37171/

But i have the next doubts:

1. What is the difference between the Code 1 and Code 2?. The Code 2 returns a bolean (to avoid the notification i think) but for me is the only difference right?:

Code 1 (In service module):
B4X:
Sub Service_Start(startingIntent As Intent)
   If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
      Dim messages() As Message
      messages = ParseSmsIntent(startingIntent)
      For i = 0 To messages.Length - 1
         Log(messages(i))
      Next
   End If
End Sub

'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
   Dim messages() As Message
   If In.HasExtra("pdus") = False Then Return messages
   Dim pdus() As Object
   Dim r As Reflector
   pdus = In.GetExtra("pdus")
   If pdus.Length > 0 Then
      Dim messages(pdus.Length) As Message
      For i = 0 To pdus.Length - 1
         r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
            Array As Object(pdus(i)), Array As String("[B"))
         messages(i).Body = r.RunMethod("getMessageBody")
         messages(i).Address = r.RunMethod("getOriginatingAddress")
      Next
   End If
   Return messages
End Sub

Code 2 (in service module):

B4X:
Sub Service_Create
    Dim SI As SmsInterceptor
    SI.Initialize2("SI", 2147483647)
End Sub


Sub SI_MessageReceived (From As String, Body As String) As Boolean
  Log("Mensaje Recibido: From= "&From& ", Body= " &Body)

  Return True
End Sub



2. If a have the two codes in a service, just the Code 1 runs. The Code 2 only work if is started in main activity with StartService(), but Code 1 not run, in other words only one code can run. Why? How can works the two codes in the same service?

3. Using the Code 1 wihtout the Smsplus library, how can i delete one SMS message?

4. For >4.4 versions what is the best code to use for delete a SMS? (with the app like default)

My apologies for my english.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Code 1 is based on a static intent filter and code 2 is based on a dynamic filter. Dynamic filters will only work when the process is running.

The dynamic filter is set when you SI.Initialize. It will not be set until the service is started.

You can delete messages with the code posted here: https://www.b4x.com/android/forum/t...ent-messages-of-the-device.38700/#post-230730

This code should also work on Android 4.4 if the app is set as the default app.
 
Upvote 0
Top