Android Question Issue on deleting SMS

sirjo66

Well-Known Member
Licensed User
Longtime User
Hello,
I have a problem deleting SMS.

Until now, on old devices, the app works well.

The APP isn't on "Google Play Store", so I don't use "intent".

On manifest I have:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.READ_SMS)
AddPermission(android.permission.WRITE_SMS)

Note that android:targetSdkVersion="22" is because so I don't need RuntimePermission, but, if I need it, I will add it

With my phone I send an SMS to myself, and then run this program:
B4X:
Dim Cellulare As String = "+39348xxxxxxx" ' here is my phone number

Log("Read SMS (" & Cellulare & ")")

Dim smsmanager As SmsMessages
Dim Lst As List = smsmanager.GetAll()

Log("There are " & Lst.Size & " messages")

Dim smsmsg As Sms
For idx = 0 To Lst.Size - 1
    smsmsg = Lst.Get(idx)
    If smsmsg.Address = Cellulare Then
        Log("delete SMS id: " & smsmsg.Id)
        smsmanager.deletesms(smsmsg.Id)
    End If
Next

But it don't delete messages

Thanks for your help

Sergio
 

DonManfred

Expert
Licensed User
Longtime User
Enable the unfiltered log and post the log. I´m positive that there is maybe something...

I can imagine it does not work on newer devices... You can stick with old devices though.

Based on this it is not possible on Devices running Android 4.4+ unless your app is the default SMS app on the Device.

The unfiltered log may reveal more infos.

Forum Search about it.

All relevant answers i found suggest the app must be the default SMS app to delete a SMS.

Other apps that only want to read new messages can instead receive the SMS_RECEIVED_ACTION broadcast intent when a new SMS arrives. However, only the app that receives the SMS_DELIVER_ACTION broadcast (the user-specified default SMS app) is able to write to the SMS Provider defined by the android.provider.Telephony class and subclasses.
As such, it's important that you update your messaging app as soon as possible to be available as a default SMS app, because although your existing app won't crash on an Android 4.4 device, it will silently fail when attempting to write to the SMS Provider.
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Here is unfiltered log

Read SMS (+393482663653)
query,matched:0, calling pid = 9971
query, match 0:Elapsed time : 1.528 ms
There are 4 messages
delete SMS id: 1584
content://sms
delete SMS id: 1583
content://sms
query,matched:4, calling pid = 17272
query, match 4:Elapsed time : 1.204 ms
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Based on this it is not possible on Devices running Android 4.4+ unless your app is the default SMS app on the Device.

Yes, I knowed this, but I hoped that was only for apps on "Google Play Store"

Well, I will change with "broadcast intent"

Entering in searching mode........

Many thanks for your patience

Sergio
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I want also try another way.
I readed that apps like whatsapp can receive a "special sms", with a fixed format, for (example) activate the app.
So, the app can read and delete this SMS.
I try to search this thread with words like "whatsapp", "sms", "special", and so on but I don't find it
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I readed that apps like whatsapp can receive a "special sms", with a fixed format, for (example) activate the app.
So, the app can read and delete this SMS.
No.

It uses the SMS Retriever Api.

 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @sirjo66 ,
are you aware that your full phone number is visible in post #3 ? AFAIK, forum pages are idexed by search engines, so that number will be soon in the public domain
 
Upvote 0
Top