Comments (11)
Sry that I'm only able to answer now. I removed the AwesomeNotificationService and ContentExtension but without success. The notification is still not received. Only when I remove the plugin completely, is it received again.
from awesome_notifications.
Yes! I saw your fork.
And don't worry. Each project has its own needs, I'm glad you bring your own.
Have you encountered a problem using notifications with FCM and other Firebase services?
from awesome_notifications.
No, it all works.
Previously I had my own native Android implementation to handle Notifications.
Now with firebase_messaging 8 you can handle background notification with Flutter as well.
So I migrate to using that and you plugin but disabled your fcm part.
I tried doing the same for iOS but it didn't work/ I'm not sure what code I have to remove for your plugin to not handle fcm notifications. I can receive Notification on iOS send from the firebase console but not ones that I send from my server, these include a data payload.
from awesome_notifications.
This is very interesting! I want to see how they do with iOS dart background executions.
I do not design this plugin to be disabled like this. I will study how this can be done.
from awesome_notifications.
Thanks,
the only reason I need this is because I have my own data structure for the notification payload and your plugin requires to use yours.
But again your plugin is great, I love the notification customizations!
from awesome_notifications.
Can you send me an example of your payload content?
I had believed that a Map<String, String> was enough for the applications.
from awesome_notifications.
{
"messageType": "newYoutubeVideo",
"id": "xmw2C02Oyb4",
"channelId": "UCH-_hzb2ILSCo9ftVSnrCIQ",
"channelName": "Yogscast Lewis & Simon",
"duration": "14:43",
"videoId": "xmw2C02Oyb4",
"videoTitle": "NEW ROLE: DETRAITOR | Gmod TTT",
"date": "1604862527499",
"publishedMills": "1604862527499",
"creatorNames": "[Lewis,Ben,Duncan,Rythian,Daltos,Pedguin,Zylus,Zoey",
"creatorKeys": "[-LO4RXOIYbfmHBxRQsb3,-LV7p9gJgRCO5ubEAZ9M,-LO4RgjL5OZNOMyZl3PT,-LO4tVwQPgtV5jYenvzr,-LOFjRQqUxcLcDGtZrRQ,-LOFfpUuNnXTb2rMmbYr,-LOFATAWo-IgqWFpGVxM,-LO4RmRnLAcMCTUfnGqR]",
"creator": "["
"{\"name\":\"Lewis\",\"key\":\"-LO4RXOIYbfmHBxRQsb3\"},"
"{\"name\":\"Ben\",\"key\":\"-LV7p9gJgRCO5ubEAZ9M\"},"
"{\"name\":\"Duncan\",\"key\":\"-LO4RgjL5OZNOMyZl3PT\"},"
"{\"name\":\"Rythian\",\"key\":\"-LO4tVwQPgtV5jYenvzr\"},"
"{\"name\":\"Daltos\",\"key\":\"-LOFjRQqUxcLcDGtZrRQ\"},"
"{\"name\":\"Pedguin\",\"key\":\"-LOFfpUuNnXTb2rMmbYr\"},"
"{\"name\":\"Zylus\",\"key\":\"-LOFATAWo-IgqWFpGVxM\"},"
"{\"name\":\"Zoey\",\"key\":\"-LO4RmRnLAcMCTUfnGqR\"}"
"]"
}
Some fields are a bit redundant but this is one of the notification types I'm sending.
from awesome_notifications.
I have done one more experiment.
I removed your plugin completly and tried sending notifications with success.
After reading it it stopped working.
If it helps here is part of my main.dart and handle_notifications.dart
(I did a lot of prints sry)
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("Handling a background message ${message.messageId}");
print("Handling a background message ${message.data}");
handleNotifications(message);
}
void main(List<String> args) async {
YRouter.init(f.FluroRouter());
WidgetsFlutterBinding.ensureInitialized();
try {
await Firebase.initializeApp();
print('initializeApp');
} catch (e) {
print('initializeApp: $e');
}
try {
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen(firebaseMessagingBackgroundHandler);
print('init fcm listener');
} catch (e) {
print('init fcm listener: $e');
}
/// Update the iOS foreground notification presentation options to allow
/// heads up notifications.
try {
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
print('setForegroundNotificationPresentationOptions');
} catch (e) {
print('setForegroundNotificationPresentationOptions: $e');
}
// Pass all uncaught errors to Crashlytics.
// FlutterError.onError = Crashlytics.instance.recordFlutterError;
runApp(
NotificationHandler(
child: NewRoot(
child: App(),
),
),
);
}
handle_notification.dart
Future<void> handleNotifications(RemoteMessage remoteMessage) async {
Map<String, String> data = remoteMessage.data;
print('data: $data');
String messageType = data['messageType'];
print('handleNotifications');
print('messageType: $messageType');
print(remoteMessage.data);
if (messageType == null) {
return null;
}
switch (messageType.toLowerCase()) {
case "newyoutubevideo":
return showFirebaseNewYoutubeVideoNotification(remoteMessage);
case 'twitchchannellive':
return showFirebaseTwitchChannelLiveNotification(remoteMessage);
case 'other':
print('other');
showFirebaseNotification(remoteMessage);
break;
}
}
class NotificationHandler extends StatefulWidget {
final Widget child;
const NotificationHandler({Key key, @required this.child}) : super(key: key);
@override
_NotificationHandlerState createState() => _NotificationHandlerState();
}
class _NotificationHandlerState extends State<NotificationHandler> {
StreamSubscription _onMessage;
StreamSubscription _createdStream;
StreamSubscription _displayedStream;
StreamSubscription _actionStream;
StreamSubscription _dismissedStream;
StreamSubscription _ANfcmToken;
StreamSubscription _fcmToken;
@override
void initState() {
_init();
super.initState();
}
@override
void dispose() {
_onMessage?.cancel();
_createdStream?.cancel();
_displayedStream?.cancel();
_actionStream?.cancel();
_dismissedStream?.cancel();
_fcmToken?.cancel();
_ANfcmToken?.cancel();
super.dispose();
}
void _init() async {
print('NotificationHandler _init');
await _initChannel();
try {
_createdStream = AwesomeNotifications().createdStream.listen(_created);
print('NotificationHandler _init 1');
_displayedStream =
AwesomeNotifications().displayedStream.listen(_displayed);
print('NotificationHandler _init 2');
_actionStream = AwesomeNotifications().actionStream.listen(_action);
_dismissedStream =
AwesomeNotifications().dismissedStream.listen(_dismissed);
print('NotificationHandler _init 3');
_ANfcmToken =
AwesomeNotifications().fcmTokenStream.listen((String newFcmToken) {
print("AwesomeNotifications FCM token: $newFcmToken");
});
} catch (e) {
print('NotificationHandler _init: $e');
}
try {
_fcmToken = FirebaseMessaging.instance.onTokenRefresh.listen((event) {
print('token: $event');
}, onError: (e) {
print('token error: $e');
});
print('NotificationHandler _init 4');
} catch (e) {
print('_fcmTokenStreamError $e');
}
try {
String apns = await FirebaseMessaging.instance.getAPNSToken();
print('apns $apns');
} catch (e) {
print('apns error $e');
}
print('NotificationHandler _init done');
}
Future<void> _initChannel() async {
print('_initChannel');
try {
await AwesomeNotifications().initialize(
'resource://drawable/ic_notification_y_white',
[
NotificationChannel(
channelKey: YNotificationChannel.jjNotification,
channelName: 'Jingle Jam Related Notifications',
defaultColor: YColors.jingleJam,
ledColor: YColors.jingleJam,
),
NotificationChannel(
channelKey: YNotificationChannel.pollNotification,
channelName: 'Poll Notifications',
defaultColor: YColors.primaryColor,
ledColor: YColors.primaryColor,
),
NotificationChannel(
channelKey: YNotificationChannel.otherNotification,
channelName: 'Other Notifications',
defaultColor: YColors.primaryColor,
ledColor: YColors.primaryColor,
),
NotificationChannel(
channelKey: YNotificationChannel.twitchNotification,
channelName: 'Twitch Notifications',
defaultColor: YColors.twitchPallet,
ledColor: YColors.twitchPallet,
),
NotificationChannel(
channelKey: YNotificationChannel.youtubeNotification,
channelName: 'Youtube Notifications',
defaultColor: YColors.youtubeRed,
ledColor: YColors.youtubeRed,
),
NotificationChannel(
channelKey: YNotificationChannel.otherTwitchNotification,
channelName: 'Other Twitch Notifications',
defaultColor: YColors.twitchPallet,
ledColor: YColors.twitchPallet,
),
NotificationChannel(
channelKey: YNotificationChannel.otherYoutubeNotification,
channelName: 'Other Youtube Notifications',
defaultColor: YColors.youtubeRed,
ledColor: YColors.youtubeRed,
),
NotificationChannel(
channelKey: YNotificationChannel.twitterNotification,
channelName: 'Twitter Related Notifications',
defaultColor: YColors.primaryColor,
ledColor: YColors.primaryColor,
),
NotificationChannel(
channelKey: YNotificationChannel.merchNotification,
channelName: 'Merch Related Notifications',
defaultColor: YColors.primaryColor,
ledColor: YColors.primaryColor,
),
],
);
print('init channel');
} catch (e) {
print('init channel: $e');
}
}
void _created(ReceivedNotification notification) {
print('notification created ${notification.id}');
}
void _displayed(ReceivedNotification notification) {
print('notification displayed ${notification.id}');
}
void _action(ReceivedAction action) async {
print(
'notification action pressed ${action.buttonKeyPressed}, ${action.id}');
if (action.channelKey == YNotificationChannel.youtubeNotification) {
YoutubeNotification youtubeNotification = YoutubeNotification.fromMap(
{
for (String key in action.payload.keys) key: action.payload[key],
},
);
if (action.buttonKeyPressed == null) {
if (await canLaunch(
'https://www.youtube.com/watch?v=${youtubeNotification.videoId}')) {
launch(
'https://www.youtube.com/watch?v=${youtubeNotification.videoId}');
} else {
print('can not launch');
}
} else if (action.buttonKeyPressed == 'open_youtube') {
if (await canLaunch(
'https://www.youtube.com/watch?v=${youtubeNotification.videoId}')) {
launch(
'https://www.youtube.com/watch?v=${youtubeNotification.videoId}');
} else {
print('can not launch');
}
} else if (action.buttonKeyPressed == 'later') {
SharedPreferences prefs = await SharedPreferences.getInstance();
int min = prefs.getInt('youtubeNotificationLater') ?? 60;
showYoutubeNotification(
youtubeNotification,
schedule: DateTime.now().add(Duration(minutes: min)),
);
}
}
}
void _dismissed(ReceivedAction action) {
print('notification dismissed ${action.id}');
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}
from awesome_notifications.
Firebase cloud message scripts fires the notifications globally across the app. To "disable" my plugin you just need to make the fcmservice.java do nothing.
I gonna implement a switch to make my plugin ignore it by default until you activate it intentionally. What do you think?
from awesome_notifications.
Yeah something like
AwesomeNotifications().enableFCM(bool enable);
sounds good.
I have disabled it on android do I have to do something on iOS? Since it is currently not working with your plugin added to the pubsec.yaml. If I remove it and all references to it, then I receive Notifications.
from awesome_notifications.
Just write your own Service Extension Target and the plugin will not process the notification.
from awesome_notifications.
Related Issues (20)
- Readme flutter_background_fetch dose not exist HOT 1
- Cancel only the next notification occurrence in repeat mode HOT 1
- Custom Sound is not working when app is in background or terminated HOT 1
- me.carda:AndroidAwnCore not found HOT 5
- [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(SHARED_PREFERENCES_NOT_AVAILABLE, class c3.b isn't parameterized, sharedPreferences.get, null) HOT 4
- NullPointerException: Context.getPackageName()' on a null object reference HOT 1
- How to receive / show payload from fcm (awesome_notifications_fcm) HOT 1
- requestPermissionToSendNotifications() not returning when sent to app notification settings HOT 2
- intl package version conflict with other packages HOT 1
- Some awesome notifications warnings when running the app
- Pod install warnings caused by 0.9 pod modifications changes HOT 2
- Allow setting android's notification "priority"
- Notification channel 'scheduled' does not exist.
- Background Notification not displaying HOT 1
- "[Demo]" appended in the subject of android device HOT 2
- How to use `onBackgroundMessage` function similar to `FirebaseMessaging` HOT 1
- How can awesome_notifications wake up the screen and make notifications when the screen is off
- iOS. Schedule Notification StartDate EndDate and Interval issue
- How do I set a different background color icon?
- createNotification returns false on Android
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 awesome_notifications.