Closed rgodlontonshaw closed 4 years ago
Hi @rgodlontonshaw,
It appears your project has been updated to version 1.1.2
of the pushy_flutter
Dart package. This new version invokes your notification listener in the background, even if your app is not running, allowing you to generate a notification from Dart code. It requires a slight code change.
To update your project to the new Pushy Flutter SDK:
1) Please ensure your Flutter Android project has been updated to Flutter 1.12+
for compatibility with the new version of our plugin. Your android/app/src/main/AndroidManifest.xml
should contain a <meta-data>
attribute labeled flutterEmbedding
with a value of 2
.
2) Remove the following lines from your android/app/src/main/AndroidManifest.xml
:
<!-- Pushy Notification Receiver -->
<!-- Incoming push notifications will invoke the following BroadcastReceiver -->
<receiver android:name="me.pushy.sdk.flutter.PushReceiver" android:exported="false">
<intent-filter>
<!-- Do not modify this -->
<action android:name="pushy.me" />
</intent-filter>
</receiver>
3) Remove any existing Pushy.setNotificationListener((data) => {})
method from your application.
4) Add the following method to your main.dart
file, right after the import
statements, and outside any Widget
class declaration, to process push notifications in the background via a Flutter background isolate:
// Please place this code in main.dart,
// After the import statements, and outside any Widget class (top-level)
void backgroundNotificationListener(Map<String, dynamic> data) {
// Print notification payload data
print('Received notification: $data');
// Notification title
String notificationTitle = 'MyApp';
// Attempt to extract the "message" property from the payload: {"message":"Hello World!"}
String notificationText = data['message'] ?? 'Hello World!';
// Android: Displays a system notification
// iOS: Displays an alert dialog
Pushy.notify(notificationTitle, notificationText, data);
// Clear iOS app badge number
Pushy.clearBadge();
}
Feel free to modify this sample code to suit your own needs.
5) Call the Pushy.setNotificationListener(backgroundNotificationListener)
method after Pushy.listen()
to configure the background notification listener:
// Listen for push notifications received
Pushy.setNotificationListener(backgroundNotificationListener);
Please let us know if it resolves the issue.
Thanks so much for your response @pushy-me.
I've implemented everything as above. I get this back in my console:
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): Failed to handle method call
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at me.pushy.sdk.flutter.PushyPlugin.setNotificationListener(PushyPlugin.java:377)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at me.pushy.sdk.flutter.PushyPlugin.onMethodCall(PushyPlugin.java:134)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at android.os.Looper.loop(Looper.java:181)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at android.app.ActivityThread.main(ActivityThread.java:7073)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#me.pushy.sdk.flutter/methods(29989): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
E/flutter (29989): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(error, java.lang.Integer cannot be cast to java.lang.Long, null)
Thanks for the bug report, it seems that some versions of the Flutter engine are providing callback handles as Integer
. We've deployed a fix in 554de16 and published in 1.1.3
.
To update your project to the new Pushy Flutter SDK:
1) Install version 1.1.3
of our Flutter SDK by editing the pubspec.yaml
in the root directory of your project and adding the following under the dependencies section:
pushy_flutter: 1.1.3
Run flutter pub get
to fetch the dependency. Then, run your app and check if the Dart notification listener is invoked in the background.
Thanks so much. @pushy-me I've upgraded to version 1.1.3
No errors come through now but I am still not getting in any notifications at all?
D/Pushy (20875): Initializing FlutterBackgroundExecutor background isolate
D/NetworkManagementSocketTagger(20875): tagSocket(131) with statsTag=0xffffffff, statsUid=-1
D/Pushy (20875): Isolate called notificationCallbackReady()
[{"id":14,"result":{"value":"android","type":"_extensionType","method":"ext.flutter.platformOverride"}}]
[{"id":16,"result":{"timeDilation":"1.0","type":"_extensionType","method":"ext.flutter.timeDilation"}}]
[{"id":17,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.debugPaint"}}]
[{"id":18,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.debugPaintBaselinesEnabled"}}]
[{"id":19,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.repaintRainbow"}}]
[{"id":20,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.showPerformanceOverlay"}}]
[{"id":21,"result":{"enabled":"true","type":"_extensionType","method":"ext.flutter.debugAllowBanner"}}]
[{"id":22,"result":{"enabled":"true","type":"_extensionType","method":"ext.flutter.debugAllowBanner"}}]
[{"id":23,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.inspector.structuredErrors"}}]
[{"id":24,"result":{"enabled":"true","type":"_extensionType","method":"ext.flutter.inspector.structuredErrors"}}]
[{"id":25,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.inspector.show"}}]
[{"id":26,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.inspector.trackRebuildDirtyWidgets"}}]
[{"id":27,"result":{"enabled":"false","type":"_extensionType","method":"ext.flutter.inspector.trackRepaintWidgets"}}]
[{"id":15,"result":{"value":"android","type":"_extensionType","method":"ext.flutter.platformOverride"}}]
D/Pushy (20875): Connected successfully (sending keep alive every 300 seconds)
Hi @rgodlontonshaw, Can you please ensure you are sending notifications to the right device token?
Please check the logs for the following line:
D/Pushy (20875): Device Token: ..........................
Then, try to send a notification to that device token on this page: https://pushy.me/docs/android/send-test-notification
Perfect! Thanks so much @pushy-me. It's working now. 👍
Hi there,
Please could you assist me. I have upgraded my Flutter SDK and Pushy library (pushy_flutter: ^1.1.2) recently and now I no longer receive any push notifications. I am using the flutter pushy demo code exactly.
I see this error in my logs. I/flutter (18015): Pushy: Error retrieving handle for Flutter callbacks
I have tried everything I possibly can think of. The notifications were working before on iOS and Android. Any advice/guidance/assistance would be much appreciated.
Flutter doctor: