Issue in Displaying Notification with awesome_notifications in Flutter - flutter

I am new to flutter.I have started to create a reminder app.I am trying to call a push notification on android alarm call back.I am using awesome_notifications. On call back I am calling _ringAlarm().I have pasted it below.
It says D/NotificationSender( 5192): Notification created, but nothing shows on screen.
This exception was thrown while running:
W/System.err( 5192): java.lang.IllegalArgumentException: Invalid
notification (no valid small icon): Notification(channel=basic_channel
shortcut=null contentView=null vibrate=null sound=null tick
defaults=0x0 flags=0x11 color=0xff9d50dd vis=UNKNOWN(2))
Future _ringAlarm() async {
AwesomeNotifications().initialize(
'resource://drawable/logo.png',
[
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
ledColor: Colors.white
)
]
);
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'Simple Notification',
body: 'Simple body'
)
);
}

That means that you had some problems with your icon to solve this problem you have to add an icon under "[project]/android/app/src/main/res/drawable/" named "logo.png". drawable position image
When initializing you must insert only the name without the extension like this
AwesomeNotifications().initialize(
'resource://drawable/logo',
[
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
ledColor: Colors.white
)
]
);
Right now the only method available is via resource

On top of Workflop's answer, I also had to uninstall the app from my phone, then run the installation again on Android Studio.
I had the same issue when adding an image to my app. It seems to be related to the debug cache.
I also found out that the source image is extremely restricted, but somehow this is not explained in the Awesome Notifications repo. Apparently, images must be 120x120 resolution at max and contain only simple graphics, not including pasted images. It only worked for me with text and vectorial graphics.

Related

How can I use phone notification and custom sound in my awsome notification in flutter

Hello Guys I am working on my flutter project Where I am using awesome notification. I want to do two things.
The device notification sound will be the sound source.
The custom sound provided by me will be the sound source.
I don't know How to do point 1. However for point 2 I added notification.mp3 file in my asset folder and give soundSource: 'assets/notification.mp3'
My Notification initialize Code:
AwesomeNotifications().initialize(
null,
[
NotificationChannel(
channelKey: 'key1',
channelName: 'Recipedia',
channelDescription: 'Testing Notification',
defaultColor: const Color(0XFFff735c),
ledColor: const Color(0XFFff735c),
soundSource: 'assets/notification.mp3',
enableLights: true,
enableVibration: true,
playSound: true,
)
],
);
My createNotification code:
void OTPNotification() async {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1,
channelKey: 'key1',
title: 'Recipedia',
body: 'We have sent you a OTP code. Please check your email.',
bigPicture: 'assets/OTP1.png',
notificationLayout: NotificationLayout.BigPicture,
)
);
}

How do I show a notification when app is closed?

I saw different question regarding this topic like this one:
Flutter send local notification when app is closed (alarm)
Some of them with accepted answers but nothing seems to work with latest version. Notification package has changed and all of these examples are deprecated.
I tried actual version (flutter_local_notifications: ^12.0.0) and as soon as I close the app I don't receive any notification at all.
const AndroidNotificationChannel channel = AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
importance: Importance.high,
);
var detroit = tz.getLocation('America/Detroit');
var now = tz.TZDateTime.now(detroit);
await _flutterLocalNotificationsPlugin.zonedSchedule(
0,
'scheduled title',
'scheduled body',
tz.TZDateTime.now(now.location).add(const Duration(seconds: 5)),
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
The only notifications that I implemented in the background are the ones coming from firebase cloud functions, but I don't want to rely on this for simple notifications (specially because of the plan).
Is there anything working out there?
This was already working. The trick was to not test on debug:
flutter run --release

Open app on firebase notification received in flutter

I want to open the application automatically when a firebase notification is received, without user interaction. means when my application is killed or in the background and when the user receives a firebase notification the application should open automatic without user interaction or clicking on the notification is this possible in the flutter
I want to add this feature in the video calling application that when I receive a notification the call screen with accept reject button should render and I also want to add the autoanswer feature in it.
You can achieve this in Android but Its not possible in iOS for now, For android its Full-screen intent notifications and for iOS most you can do is set an custom ringtone when notification is received, You can use the below mentioned library for most of your notification needs:-pub.dev/packages/flutter_local_notifications
yes, obviously it's possible
u can do like this
demo video link : click here for watch video
Future<void> _showNotification() async {
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
'your channel id',
'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
priority: Priority.high,
icon: '#mipmap/ic_launcher',
// playSound: false,
);
const NotificationDetails platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics,
);
await flutterLocalNotificationsPlugin.show(
0,
'plain title',
'plain body',
platformChannelSpecifics,
payload: 'item x',
);
}

Flutter awesome notification click open specific page

I am using Flutter awesome notifications. When the notification is clicked when the application is closed, I want to direct it to a special page within the application. What is the easiest way for me to do this?
To do this, firstly you need to initialize AwesomeNotifications before runApp and then simply put a listner to listen to the notification click:
Initialize:
AwesomeNotifications().initialize(
'resource://drawable/logo_circle_notification',
[
NotificationChannel(
channelGroupKey: 'normal_channel_group',
channelKey: 'normal_channel',
channelName: 'Normal Notifications',
channelDescription: 'Notification channel for normal notifications',
defaultColor: const Color(0xFF9D50DD),
ledColor: Colors.white
),
],
channelGroups: [
NotificationChannelGroup(
channelGroupkey: 'basic_channel_group',
channelGroupName: 'Basic group'),
],
debug: true
);
Listen:
listenActionStream(){
AwesomeNotifications().actionStream.listen((receivedAction) {
var payload = receivedAction.payload;
if(receivedAction.channelKey == 'normal_channel'){
//do something here
}
});
}
you can put that lister in the initState of your splash screen or something before navigating to Home Screen of the app.

How to schedule notification at specific time using awesome package in Flutter?

I am using an awesome Package and am trying to make a notification at a specific time using this package.
Future<void> showNotificationWithIconsAndActionButtons(int id) async {
AwesomeNotifications().initialize(
'',
[
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
ledColor: Colors.white,
playSound: true,
importance: NotificationImportance.Max,
defaultRingtoneType: DefaultRingtoneType.Notification,
)
]
);
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: 'basic_channel',
title: 'Anonymous says:',
body: 'Hi there!',
payload: {'uuid': 'user-profile-uuid'},
displayOnBackground: true,
displayOnForeground: true,
),
i need to make notification in particular time.
The same plugin provides a way to schedule notifications as per the need.
Checkout this link from it's description:
https://pub.dev/packages/awesome_notifications#scheduling-a-notification
Bascially showing it at a specific time will look something like this:
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: 'scheduled',
title: 'Just in time!',
body: 'This notification was schedule to shows at ' +
(Utils.DateUtils.parseDateToString(scheduleTime.toLocal()) ?? '?') +
' $timeZoneIdentifier (' +
(Utils.DateUtils.parseDateToString(scheduleTime.toUtc()) ?? '?') +
' utc)',
notificationLayout: NotificationLayout.BigPicture,
bigPicture: 'asset://assets/images/delivery.jpeg',
payload: {'uuid': 'uuid-test'},
autoCancel: false,
),
schedule: NotificationCalendar.fromDate(date: scheduleTime));
Note: The code sample is from the plugin's Readme. I have not tested this yet.
Timer.periodic(Duration(minutes: 1), (timer) {
if (DateTime.now()== DateTime.parse("2021-07-20 20:18:04Z")){// 8:18pm
return showNotificationWithIconsAndActionButtons();
}
});
This will let it check the time every minute.