Android Question Firebase Push Notifications not working with SDK 34 and Missing Foreground Service type

mcqueccu

Well-Known Member
Licensed User
Longtime User
What is the best way to send FCM using SDK 34 (Android 14 Devices) with FCM v1 and get the messages delivered.


0. BACKGROUND AND TESTS
Since the push for SDK 34 usage from Google, and the Firebase v1 coming into inception, I have been having issues with sending of notifications.

Thanks to @Erels for updating the example and B4J Sending tool found here https://www.b4x.com/android/forum/threads/b4x-firebase-push-notifications-2023.148715/

1. ISSUE
When I change the example project to use SDK 34, the notifications do not come. It can be replicated easily. Change the example project to SDK 34, install the app FRESH (using new package name, or remove the old app and reinstall), and allow the notifications permission.
Next with your B4J Sending tool properly configured to V1, try sending message.

2. I received this message also from Play Console Crash/ANR Section
Missing foreground service type
From Android 14, developers must specify service types when foreground services are found in their app's manifest. A version of your app that is currently in production is crashing because it tries to start a foreground service when no foreground service type is declared. Make sure service types for the services that start in the foreground are specified in your app's manifest

I checked the forum for Missing Foreground service type and came accross this thread https://www.b4x.com/android/forum/t...-google-play-crash-report.163821/post-1004700 and when I add this line to the manifest using SDK 34, the messages started coming

B4X:
AddPermission(android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING)
SetReceiverAttribute(FirebaseMessaging, android:foregroundServiceType, "remoteMessaging")

But then, if you upload your BUILD with this manifest code, Play Console will prompt you to make a DECLARATION about purpose of the foreground service and a mandatory video url to demonstrate how the messaging works.
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
1. There was no Error Message.
I used the Push client example from here https://www.b4x.com/android/forum/threads/b4x-firebase-push-notifications-2023.148715/

I only added changed the package name and added google-services.json
Here is the log when you start the App
B4X:
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
sending message to waiting queue of uninitialized activity (subscribetotopics)
*** Receiver (firebasemessaging) Receive (first time) ***
TokenRefresh: cQVdwZ**********WPqsubY
*** Receiver (firebasemessaging) Receive  ***
TokenRefresh: cQVdwZ**********WPqsubY
** Activity (main) Resume **
android.permission.POST_NOTIFICATIONS: true

Here is how to test
a. Remove the App from the Device
b. Change the Target SDK to 34 and run on Android 14 device, 👎The notification does not come


c. Remove the App from the Device
d. Change Target SDK 33 and run on Android 14 device, Notification works ✅


2. Yes, its is using a receiver
 
Upvote 0

fernando1987

Active Member
Licensed User
Hello, try sending the notifications with this tool at the end of the first post, this is the installer
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Just tested the example on Android 14 and 15, and it works. With targetSdkVersion=34.

I then uninstalled the app and ran it and it indeed didn't receive the notification. I ran it again and from there on it did receive the notification. I don't think that this behavior is related to the implementation. It is probably some kind of an OS limitation related to uninstalling and reinstalling.
 
Upvote 0
Top