Android Question intercepts received sms doesn't work !

Edyab

Member
Licensed User
Longtime User
Can anyone give me an example on how to write a background (as Service) application that intercepts received sms without notification.
here is my code but its not called when a sms is received (i am new to b4a):

Activity
---------------
Sub Activity_Create(FirstTime As Boolean)
StartService(Service1)
End Sub

Service
---------------
Sub Service_Create
Dim SI As SmsInterceptor
SI.Initialize2("SI", 999)
End Sub

Sub SI_MessageReceived (From As String, Body As String) As Boolean
SaveText(From & " : " & Body)
Return True
End Sub

I wrote SI_MessageReceived sub , should it be registered anywhere or automatically created by a tool ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Do you see in the log that the service is started and never destroyed ?
Better to use also Service.StartForeground in Service_Create to ensure the service is not killed by the operating system.
Do you have other SMS application running on the device that could have higher priority than your code ?

Marco
 
Upvote 0

Edyab

Member
Licensed User
Longtime User
Do you see in the log that the service is started and never destroyed ?
Better to use also Service.StartForeground in Service_Create to ensure the service is not killed by the operating system.
Do you have other SMS application running on the device that could have higher priority than your code ?

Marco

yes i have other sms application , but how can i put my service priority higher than that app?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
yes i have other sms application , but how can i put my service priority higher than that app?

it seems you can't ...
You use "999" that should be the highest priority bu as a matter of fact some SMS application overcome this
 
Upvote 0

Edyab

Member
Licensed User
Longtime User
I Uninstalled the app , now the service works great :( ,
anyone has any idea how can I get the received sms before that app? that application is "GOSMS" and it doesnt let me receive the sms.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Set the priority to 2147483647. This is the highest possible value. It doesn't matter whether it is a dynamic or static receiver.
If I were "GoSMS" developer I too would use the highest possible priority, so I think it is unpredictable who would win. Am I right ?
Marco
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
I can confirm with you (*) that normally the app which was installed first will be receiving the SMS, if both of them have same priority. But for GoSMS case, they are doing some thing more (together with setting priority at highest value 2147483647), which is unknown so far by many developers. If you make a search in Stackoverflow you will see that many people raised same question as yours.

(*) It is easy to check. I did make 2 different apps (but actually they are the same, only the names / packages are different) and installed them in different ways to compare. I did spend nearly a week just to observe.
 
Upvote 0
Top