I would like to create a service that make the phone ringing when a bluetooth device goes out of range.
The point is this: how can I make the service running without any visible gui ?
I tried this code:
This works but if I press the Overview I can still see the app.
Anyway after about 1 minutes since the phone is sleeping the debugger of B4A disconnects. I don't know if it is just the debugger to disconnect itself or the app dies.
The point is this: how can I make the service running without any visible gui ?
I tried this code:
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: 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.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Log("OK_1")
Activity.LoadLayout("Main")
CallSubDelayed("","CloseActivity")
StartService(Trova)
End Sub
Sub CloseActivity
Activity.Finish
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
B4X:
#Region Service Attributes
#StartAtBoot: False
#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 BTAdmin As BluetoothAdmin
Dim BTSerial1 As Serial
Dim BTFoundDevices As List
Type BTNameAndMac (Name As String, MAC As String)
Dim connectiontimer As Timer
Dim found As Boolean=False
Dim countdown As Int=0
Dim MP As MediaPlayer
End Sub
Sub Service_Create
BTAdmin.Initialize("BTAdmin")
BTSerial1.Initialize("BTSerial1")
Log("Start")
End Sub
Sub Service_Start (StartingIntent As Intent)
If countdown<20 Then countdown=countdown+1
If found=True Then countdown=0
Log(countdown)
If countdown>=6 Then
MP.Initialize
MP.Load(File.DirAssets, "Suono.wav")
MP.Play
End If
found=False
BTFoundDevices.Initialize
BTAdmin.StartDiscovery
End Sub
Sub Service_Destroy
End Sub
Sub BTAdmin_DiscoveryFinished
StartServiceAt("Trova",DateTime.Now + 20000,True)
End Sub
Sub BTAdmin_DeviceFound (Name As String, MacAddress As String)
Log(Name & ":" & MacAddress)
If MacAddress="D1:00:00:01:FF:FF" Then
found=True
End If
End Sub
This works but if I press the Overview I can still see the app.
Anyway after about 1 minutes since the phone is sleeping the debugger of B4A disconnects. I don't know if it is just the debugger to disconnect itself or the app dies.