Android Question Intercept SMS messages without notification (Device ON/OFF)

MarcoRome

Expert
Licensed User
Hi all. I have this code that work without problem if device is ON.

You need to initialize SmsInterceptor in Service_Create:

B4X:
Dim SI AsSmsInterceptor
SI.Initialize2("SI", 999)
And then handle the event:

B4X:
Sub SI_MessageReceived (From AsString, Body AsString) As Boolean
ToastMessageShow(From, True)
Return True
End Sub
In this way the device that receives the message does not "see the same" because set to "Return True" and all work if device is ON.
But if the device is OFF and we send the message, the device will turn ON will see the message.

Can i avoid this ?

Thank you
Marco
 

DonManfred

Expert
Licensed User
But if the device is OFF and we send the message, the device will turn ON will see the message.
You device will boot up when you recieve a SMS??? If i put my device OFF it stays OFF till ich push the powerbutton
 

MarcoRome

Expert
Licensed User
To explain better.
If i have the phone (which receives the message) ON, everything works fine.
If i have the phone (which receives the message) OFF. When i'm going to turn ( push powerbutton and start phone ) the phone will have received the message
 

lemonisdead

Well-Known Member
Licensed User
Excuse me. What do you mean by "start the phone" ? The screen ON/OFF or all the Android's phone ?
 

MarcoRome

Expert
Licensed User
ALL the Android phone. if the phone is ON/OFF only with screen or in pause... all work. I have this problem onyl when ALL phone is OFF
 

Beja

Expert
Licensed User
I think you should StartAtBoot the service, this way the service will be running before the message comes in after ON and the message can be intercepted :)
Not tested - not quote sure, but you try
 

MarcoRome

Expert
Licensed User
Thank's Beja but is already so and unfortunately it is not so.
When device Restart ( All ) .... after few second i have message

This is code:

B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region
 
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim nNotify As Notification
    Dim SI As SmsInterceptor
   
End Sub
Sub Service_Create
       nNotify.Initialize
       'nNotify.Icon = "icon.png"
       'nNotify.SetInfo("Medi", "Tap to open player.", TMM_Run)
       nNotify.Sound=False
       nNotify.Vibrate=False
       nNotify.Light=False
       nNotify.OnGoingEvent=True
    Service.StartForeground(1,nNotify)
    SI.Initialize2("SI", 999)
 
End Sub
 
Sub Service_Start (StartingIntent As Intent)
    ToastMessageShow("Service Start", True)
End Sub
 
Sub Service_Destroy
 
End Sub
 
'Gestisco Messaggi
Sub SI_MessageReceived (From As String, Body As String) As Boolean
 
If Body = messaggio Then
    ToastMessageShow(From, True)
    Return True
End If
 
End Sub
 
Top