backgroundMessageCallback not working on huawei push plugin
See original GitHub issueHi, I have implemented HMS push kit and everything is working fine except background message handler, Push.onMessageReceivedStream is working fine but when I send notification when app is on background I get error in backgroundMessageCallback, I get the following error
Unhandled Exception: MissingPluginException(No implementation found for method localNotification on channel com.huawei.flutter.push/method)
I am posting my code below, please let me know if any additional code required, thanks 😃
version on pubsec : huawei_push: ^5.0.2+301
My Application class
import com.huawei.hms.flutter.push.PushPlugin
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class MainApplication : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
PushPlugin.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
registry?.registrarFor("com.huawei.hms.flutter.push.PushPlugin");
}
}
My HMS helper function ( which I call on main.dart)
static void backgroundMessageCallback(RemoteMessage remoteMessage) async {
String data = remoteMessage.data;
Push.localNotification({
HMSLocalNotificationAttr.TITLE: '[Headless] DataMessage Received',
HMSLocalNotificationAttr.MESSAGE: 'Hello My Name'
});
print("onRemoteMessageReceived" + " Data: " + data);
}
static initNotification() async {
TokenEventChannel.receiveBroadcastStream()
.listen(_onTokenEvent, onError: _onTokenError);
Push.onNotificationOpenedApp.listen(_onNotificationOpenedApp);
var initialNotification = await Push.getInitialNotification();
Push.onMessageReceivedStream
.listen(_onMessageReceived, onError: _onMessageReceiveError);
bool backgroundMessageHandler =
await Push.registerBackgroundMessageHandler(backgroundMessageCallback); // returns true
await Push.getToken("");
await Push.turnOnPush();
}
`
manifiest
<
application
android:name=".MainApplication"
<!-- Set push kit auto enable to true (for obtaining the token on initialize)-->
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true" />
<!-- These receivers are for sending scheduled local notifications -->
<receiver android:name="com.huawei.hms.flutter.push.receiver.local.HmsLocalNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name="com.huawei.hms.flutter.push.receiver.local.HmsLocalNotificationScheduledPublisher"
android:enabled="true"
android:exported="true">
</receiver>
<receiver android:name="com.huawei.hms.flutter.push.receiver.BackgroundMessageBroadcastReceiver"
android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.huawei.hms.flutter.push.receiver.BACKGROUND_REMOTE_MESSAGE" />
</intent-filter>
</receiver>
<provider
android:authorities="${applicationId}.HMSContentProvider"
android:name="com.huawei.hms.flutter.analytics.AnalyticsContentProvider"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
build grade
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
flatDir { dirs 'libs' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
The Huawei Push Kit Integration in Flutter App - Part 01
In this article, we can discuss how to integrate our HMS Push Kit in a Flutter application. This article consist of two parts....
Read more >huawei_push 5.0.2+304 | Flutter Package - Pub.dev
HUAWEI Push Kit plugin for Flutter that exposes all the functionality provided by the HUAWEI Push Kit SDK.
Read more >flutter Huawei: push The serviceConnection has been bind for ...
adb logcat -v threadtime 1> D:\hwpush.log. 2)Reproduce the problem scenario. 3)Press Ctrl+C to complete log capture.
Read more >Huawei Push Kit Flutter Plugin - Morioh
HUAWEI Push Kit plugin for Flutter that exposes all the functionality provided by the HUAWEI Push Kit SDK. ... Questions or Issues.
Read more >Sending Push Notifications on Flutter with Huawei ... - Medium
Recently we released the Huawei Push Kit Plugin for Flutter to make the ... You can refer to this article if you came...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @aktug
Finally got it working with flutterEmbedding v2, after registering the plugin manually in my application class. Below is my updated application class
I think we have manually register the v1 plugins in v2 projects in order to use them.
I know its an old and closed issue, but just for an update so if may help anyone, I ended up using flutter local notification plugin along with this plugin for handling data payload. 😃