Android Question Receivers and HttpJob


Active Member
Licensed User
Longtime User
Hello all,

I have an app that needs to upload some info (a few bytes) to my server after receiving a push from Firebase.
As per the new restrictions on services, I have moved all the relevant code to a receiver.
The push is received OK, then the code executes until it tries to do the upload with an HttpJob. There I get a crash with a ForegroundServiceStartNotAllowedException.

I've been searching on the forum, and from what I gather here it should work:
Am I missing something?

The code is quite simple:
Sub fm_MessageArrived(Message As RemoteMessage)
    Dim messageData As Map
    Dim action As String, targetDevice As Int
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    messageData = Message.GetData
    targetDevice = messageData.Get("device_id")
    If ((targetDevice<>Settings.RegNumber) And (targetDevice<>0)) Then
    End If
End Sub

Private Sub fmSendSettings()
    Dim sMsg, JSONString As String
    Dim js As JSONGenerator
    Dim j As HttpJob
    'js is a properly constructed json
    JSONString = js.ToString
    msg = JSONString
    j.Initialize("", Me)
    j.PostString(Settings.ServerbaseUrl & Settings.SyncUrlFile, msg)
    Wait For (j) JobDone(j As HttpJob)
    If (j.Success) Then
        Log ("Get string:" & CRLF & j.GetString)
    End If
End Sub

I'd be really thankful for any help / pointers