Comments (6)
Hi @calvinmuller,
It appears your project has been updated to version 1.1.1
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.
To update your project to the new Pushy Flutter SDK:
- Install version
1.1.1
of our Flutter SDK by editing thepubspec.yaml
in the root directory of your project and adding the following under the dependencies section:
pushy_flutter: 1.1.1
Run flutter pub get
to fetch the dependency.
Note: Please ensure your Flutter Android project has been updated to Flutter 1.12+
for compatibility with this plugin. Your android/app/src/main/AndroidManifest.xml
should contain a <meta-data>
attribute labeled flutterEmbedding
with a value of 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>
-
Remove any existing
Pushy.setNotificationListener((data) => {})
method from your application. -
Add the following method to your
main.dart
file, right after theimport
statements, and outside anyWidget
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.
- Call the
Pushy.setNotificationListener(backgroundNotificationListener)
method afterPushy.listen()
to configure the background notification listener:
// Listen for push notifications received
Pushy.setNotificationListener(backgroundNotificationListener);
Please let us know if it resolves the issue.
from pushy-flutter.
Closing due to lack of response, feel free to comment to reopen.
from pushy-flutter.
@pushy-me I am noticing the same error with Flutter 2.0.6 and pushy_flutter: 2.0.1. I am following instructions from the docs, the only difference is, I am using awesome_notifications instead of the default provided by Pushy. Any idea why this could be happening?
from pushy-flutter.
Hi @gs-suresh,
What error are you seeing? Is it the following?
Isolate / notification callback IDs are missing from SharedPreferences
In that case, make sure you are calling Pushy.setNotificationListener(backgroundNotificationListener);
and passing in a global function defined in top-level main.dart
:
// 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();
}
from pushy-flutter.
Thanks @pushy-me. It turned out that the function I was using was not a global one. Switching it to a global function fixed the problem for me.
from pushy-flutter.
@gs-suresh Glad to hear! 😄
from pushy-flutter.
Related Issues (20)
- Installing background listener fails in release mode HOT 9
- iOS app killed - Click on notification not open specific screen HOT 2
- iOS Push permission deined HOT 1
- A blank screen appears when app is killed and user taps on a notification HOT 2
- Android Notification HOT 10
- Web support HOT 1
- Dialog pop in IOS when app is in foreground. HOT 2
- Infinix Mobile Notification Issue HOT 1
- Crashes and Freezes Pushy.Register() on VIVO and OPPO devices . HOT 1
- Status Bar Notification Issue In Android HOT 3
- Feature: Support for Linux HOT 1
- Pushy.register get device token giving error HOT 1
- Token is not generating Pushy in IOS HOT 3
- Android , Pushy ( 7552): Notifications have been disabled by the app HOT 2
- Please, update dependencies HOT 4
- await Pushy.register() HOT 8
- Unable to send notification on deivce id in flutter HOT 1
- Support for Notification Channel on Android HOT 3
- [Feature Request] Field to know in which lifecycle the notification received HOT 1
- Registration failed: The application identifier is missing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pushy-flutter.