Android Example Auto starting your app

arnold steger

Member
Licensed User
Longtime User
my service not open the app. what is my error?
I want read evrytime the sms, when contain "My Text send from app" then whant start my app and added a marker
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.
    Type Message (Address As String, Body As String)
    Dim TextSMSvorhanden As Boolean
   
End Sub
Sub Service_Create
    TextSMSvorhanden=False
   
End Sub

Sub Service_Start (StartingIntent As Intent)
   If StartingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
      Dim messages() As Message
      messages = ParseSmsIntent(StartingIntent)
      For i = 0 To messages.Length - 1
         Log(messages(i))
      Next
   End If
   
If Main.SucheTextSMS.Contains("(My Text send from app)") Then
        TextSMSvorhanden=True
    StartActivity(Main)
    If Main.gmapinit=True AND TextSMSvorhanden Then
    CallSubDelayed(Main,"MarkerSetzenAusSMS")
    End If
End If
           
End Sub

Sub Service_Destroy

End Sub

'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
   Dim messages() As Message
   If In.HasExtra("pdus") = False Then Return messages
   Dim pdus() As Object
   Dim r As Reflector
   pdus = In.GetExtra("pdus")
   If pdus.Length > 0 Then
      Dim messages(pdus.Length) As Message
      For i = 0 To pdus.Length - 1
         r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
            Array As Object(pdus(i)), Array As String("[B"))
         messages(i).Body = r.RunMethod("getMessageBody")
         messages(i).Address = r.RunMethod("getOriginatingAddress")
                                    Main.SucheTextSMS=r.RunMethod("getMessageBody")
      Next
   End If
   Return messages
End Sub
in activity_Main
B4X:
Sub MarkerSetzenAusSMS
Dim bez,SMStemp As String

SMStemp=SucheTextSMS.Replace("(My Text send from app)","")
Dim LL,LT As List
Dim l1,l2 As String
Dim sf As StringFunctions
sf.Initialize
LT = sf.Split(SMStemp,"-")
SMStemp=LT.Get(0)
bez=LT.Get(1)

LL = sf.Split(SMStemp,",")
l1=LL.Get(0)
l2=LL.Get(1)

gmap.AddMarker2(l1,l2, bez&" ("&l1&","&l2&")",gmap.HUE_ORANGE)
            Dim CameraPosition1 As CameraPosition
   CameraPosition1.Initialize(l1,l2, 15)
   gmap.AnimateCamera(CameraPosition1)
           
Sms.TextSMSvorhanden=False
  
End Sub
 
Last edited:

Vitt61

Member
Licensed User
Longtime User
The #StartAtBoot: True attribute adds an item to the manifest file which tells the OS that this service should be started after boot completes.

I test the app auto start but I receive this error:
B4A version 4.30
Parsing code. Error
Error parsing program.
Error description: Attribute not supported: startatboot
Occurred on line: 22
#StartAtBoot: True
In my # list I don't have "StartAtBoot"
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…