Hi bsnqt
Thanks for following this with me. I have looked at BroadcastReceiver and have attached an example I have put together using that approach - but it still does not handle the first sms message when the service starts.
Let me explain what I want in a different way. This scenario is entirely fictional as no-one would want this to happen, but it hopefully serves to describe the situation I still have.
Lets say I NEVER want to have any sms messages go into the default app on my phone - I ALWAYS want them to be intercepted and aborted. -- as I said 'entirely fictional'.
The code attached is such an app using BroadcastReceiver and the Broadcast.AbortBroadcast approach as described by yourself.
It works fine when the service is running as it catches and aborts the message from going to the default app.
But if the service is stopped for whatever reason, then it does NOT catch and abort the first sms message - it allows it to pass thru to the default handler.
The service does get started at that point and subsequent sms messages are correctly aborted.
The logging I have in place shows that when the service is NOT running, the BroadcastReceiver_OnReceive Sub is not called, Instead the only segment of the code that gets called is Service_Start. I added Sub ParseSmsIntent to allow me to see what the message body is.
It is only when the service is running that BroadcastReceiver_OnReceive is called
My test was:
Load the app
Stop the service from 'settings'
send the text "stopped" from another phone
send the text "started" from another phone
(then dont forget to uninstall the app or you will never receive another sms)
Result:
The first text is still handled by the default app, second and subsequent are aborted.
--- this is the log when the service was NOT running ---
** Service (bcreceiver) Create **
ServiceCreate
BroadcastReceiver has been initialized.
** Service (bcreceiver) Start **
service_start
into parseSMSintent
Logged in Service_Start: [Address=+64272038977, Body=Stopped, IsInitialized=false]
serviceStart completed
--- this is the log when the service WAS running ---
into BroadcastReceiver
into parseSMSintent
Logged in BroadcastReceiver_OnReceive[Address=+64272038977, Body=Running, IsInitialized=false]
received sms
android.provider.Telephony.SMS_RECEIVED
So in this fictious scenario - how to I abort that first sms !!
And a slightly late Merry Christmas to you.