How to receive Huawei push in flutter when app is killed?

610 Views Asked by At

Trying to setup Huawei push in a flutter app and encountered some problems when app is not running.

The push is received when app is running in front and background. but when it is killed, it does not receive push or sometimes not real-time or not until app is reopened.

what could be missing in here?

1

There are 1 best solutions below

0
On

When the app runs in background or app process is killed, the onMessageReceivedStream handler will not be called when receiving data messages.

Instead, you need to set up a background callback handler via the registerBackgroundMessageHandler method.

To set up a background handler, call registerBackgroundMessageHandler outside of your app logic as early as possible.

for example sample code :

package com.huawei.hms.flutter.push_example;

import com.huawei.hms.flutter.push.PushPlugin;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;



public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
    @Override
    public void onCreate() {
        super.onCreate();
        PushPlugin.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        GeneratedPluginRegistrant.registerWith(registry);
    }
}

also, double-check base integration steps in the link: