B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Service
Version=11.5
@EndOfDesignText@
#Region  Service Attributes 
  #StartAtBoot: True
  #ExcludeFromLibrary: True
  #StartCommandReturnValue: android.app.Service.START_STICKY
#End Region

Sub Process_Globals
	Dim pnreciver As PNBroadcastReceiver
	Dim awak As PhoneWakeState
	Private listener As NotificationListener
End Sub

Sub Service_Create
	Try
		awak.PartialLock
		awak.KeepAlive(False)
		listener.Initialize("listener")
		pnreciver.Initialize("pnreciver")
		pnreciver.AddAction("android.intent.action.SCREEN_ON")
		pnreciver.AddAction("android.intent.action.SCREEN_OFF")
		pnreciver.AddAction("android.intent.action.BATTERY_CHANGED")
		pnreciver.AddAction("android.provider.Telephony.SMS_RECEIVED")
		pnreciver.RegisterReceiver
	Catch
		StartService(Me)
	End Try
	
End Sub
Sub pnreciver_OnReceive(Action As String,keys() As String,Data As Object)
	Try
		If Action="android.intent.action.SCREEN_ON" Then
			StartService("")
			StartService(FirebaseMessaging)
			CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
		End If
		If Action="android.intent.action.SCREEN_OFF" Then
			StartService("")
			StartService(FirebaseMessaging)
			CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
		End If
		If Action="android.intent.action.BATTERY_CHANGED" Then
			StartService("")
			StartService(FirebaseMessaging)
			CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
		End If
		If Action="android.intent.action.TIME_TICK" Then
			StartService("")
			StartService(FirebaseMessaging)
			CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
		End If
		If Action = "android.provider.Telephony.SMS_RECEIVED" Then
			StartService("")
			StartService(FirebaseMessaging)
		End If
		StartServiceAt(FirebaseMessaging, DateTime.Now + 30000, True)
	Catch
		StartService(Me)
		StartService(FirebaseMessaging)
	End Try
End Sub
Sub Service_Start (StartingIntent As Intent)
	Try
		StartServiceAt(Me, DateTime.Now + 3 * DateTime.TicksPerMinute, False) 'in the example it was 30'
		CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
		If listener.HandleIntent(StartingIntent) Then Return
		Service.StopAutomaticForeground
	Catch
		StartService(Me)
	End Try
End Sub

Sub Service_Destroy
	Try
		StartService("")
		awak.KeepAlive(False)
	Catch
		StartService(Me)
	End Try
End Sub
