Android Question [SOLVED] smsmanager.deletesms on OS 4.2.2

sirjo66

Well-Known Member
Licensed User
Longtime User
Hello to all,

my app receive an SMS, read it, execute some actions, delete it, and send an SMS for to answer.

This is all inside a service, and it works very well !! :cool:

But now, my customer has changed the device, and the new have OS 4.2.2 :(

My app works, but can't delete SMS

I knowed this problem, and I know that I need to register my app as an intent for to receive SMS, but I don't understand it very well.
I need a "dynamic receivers" as Erel explain here, but I am a newbie.

I thinked that when my service start, it register the intent, when the service stop, de-register it.

In my service, I have these routines:
B4X:
Sub Service_Create

   server.Initialize("Server")
   server.Start(5555) ' is an http service
   Dim n As Notification
   n.Initialize
   n.Icon = "icon"
   n.SetInfo("SendSMS attivo", "", Main)
   Service.StartForeground(1, n)
   
   Timer1.Initialize("Timer1", 10000) ' 10 seconds

End Sub

Sub Timer1_Tick ' every 10 seconds.....
   Timer1.Enabled=False
   
   ' read SMS
   Dim smsmanager As SmsMessages
   Dim Lst As List
   Lst = smsmanager.GetAll()

   Dim smsmsg As Sms
   For idx = 0 To Lst.Size - 1
     smsmsg = Lst.Get(idx)
     If smsmsg.Address = "the right phone number" Then
         ' execute my action........
         smsmanager.deletesms(smsmsg.Id)   '  <<<<<< this line don't work
     End If
   Next

   Timer1.Enabled=True
End Sub

Please, can you tell me how I can register my service as an android.provider.Telephony.SMS_RECEIVED ??
But then, when an SMS is received, I need to do also or not ??

Many thanks for your help

Sergio
 

DonManfred

Expert
Licensed User
Longtime User
Maybe you need to put
AddPermission(android.permission.WRITE_SMS) ' Allows an application to write SMS messages.
in your manifest-editor. I don´t know but that´s the only permission is found which COULD fit your needs. Give it a try
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Ok, I will try, but.....
... I send SMS without problem, so I think that android.permission.WRITE_SMS already exist (I use smsplus library)

In my Samsung 4.2.2 the app works fine and delete the SMS, but in the phone of the customer (a Huawei Ascend 300 4.2.2) it don't works

Sergio
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Great !!
I hope that tomorrow I can get the phone from my customer so I can start to try it !!

Many many thanks
Sergio
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I found something interesting
he is talking about to delete the sms with a delay after you recieved the broadcast (5 seconds) cause the sms is not available in sms-store while android is doing the broadcast.

Original Post from StackOverflow:
Just have a look at this link, it will give you a brief idea of the logic:
https://gist.github.com/5178e798d9a00cac4ddb
Just call the deleteSMS() function with some delay, because there is a slight difference between the time of notification and when it is saved actually...., for details have a look at this link also..........


Maybe this could be of help!?

I did not test the hole sms-part. Just want to help ;)
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
SOLVED !!!!

No need to modify anything !!

It was only an installation problem.
In Huawei phone, when you install an apk, you need to accept permission, but then, when the program is installed, you need to accept again one-by-one.
On screen you see a list of permission that the app needs, and you need to enable it and then confirm.

Many many thanks for your help

Sergio
 
Upvote 0
Top