Skip to content

[firebase_messaging] How to handle background push messages without never opening app (e.g. after app update)? #9359

Answered by timukasr
timukasr asked this question in Q&A
Discussion options

You must be logged in to vote

Came up with following solution:
On Android side, registered android.intent.action.MY_PACKAGE_REPLACED BroadcastReceiver, which is called after app is updated. This creates new FlutterEngine:

val engine = FlutterEngine(context)
engine.dartExecutor.executeDartEntrypoint(
    DartExecutor.DartEntrypoint(
        FlutterInjector.instance().flutterLoader().findAppBundlePath(),
        "packageReplacedReceiver"
    )
)

Next registered the method on Flutter side in main.dart:

@pragma("vm:entry-point")
void packageReplacedReceiver() {
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}

So when app is updated, background handler is registered and when first push messag…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@irjayjay
Comment options

@timukasr
Comment options

@irjayjay
Comment options

@irjayjay
Comment options

Answer selected by timukasr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants