Android Question #StartAtBoot: True doesnt seem to work

Discussion in 'Android Questions' started by Kevin Hartin, Oct 14, 2019.

  1. Kevin Hartin

    Kevin Hartin Member Licensed User

    I have a php web server that happily sends Firebase Push Notifications when a new record is created for a particular customer. These appear when the Android app has been started manually, allowing clients to know when there is something demanding their attention, as the clicking of the notification opens the app and it then updates andy missing records from the web server.

    I created the following Service in the App called FirebaseMessaging, as per the tutorial. Originally #StartAtBoot was set to False, but I changed it to True in the hope that when the phone restarts any new notifications will be received without the App being started.

    Am I missing something with this whole concept? I figure it needs to run like the Gmail app, getting push notifications irrespective of the app being opened manually.

    Thanks,
    Kev

    Code:
    #Region  Service Attributes 
        
    #StartAtBoot: True
       
    #End Region

    Sub Process_Globals
        
    Private fm As FirebaseMessaging
    End Sub

    Sub Service_Create
        fm.Initialize(
    "fm")
    End Sub

    Public Sub SubscribeToTopics
        fm.SubscribeToTopic(Starter.VendorKey) 
    'you can subscribe to more topics
    End Sub

    Sub Service_Start (StartingIntent As Intent)
        
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
        Sleep(
    0)
        
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
    End Sub

    Sub fm_MessageArrived (Message As RemoteMessage)
        
    Log("Message arrived")
        
    Log($"Message data: ${Message.GetData}"$)
        
    Dim n As Notification
        n.Initialize
        n.Icon = 
    "icon"
        n.SetInfo(Message.GetData.Get(
    "title"), Message.GetData.Get("body"), Main)
        n.Notify(
    1)
    End Sub

    Sub Service_Destroy

    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Yes. The app doesn't need to run in order to receive notifications.

    If you are not receiving notifications when your app is not running (don't kill it yourself as it is a different state) then go back to the tutorial and send the messages with the B4J code. Once you get it working you can switch to your PHP code.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice