Flutter PUSH Notification icon not showing - android

I tried to add flutter app icon by using a package flutter_launcher_icon app icon is correct but icons shows in push notification show as a white box
Notification Icon Shows as a white box
Resource File
I added icons by using a package [flutter_launcher_icons]
Expected Output

same error have happened to me so i have used icon as xml file in android
we have to add that file name here
void showNotification(int orderCount) async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid = AndroidInitializationSettings('fav_icon');
var initializeSettings = InitializationSettings(android: initializationSettingsAndroid);
var res = await flutterLocalNotificationsPlugin.initialize(initializeSettings) ?? false;
Log.d("Notification manager initialized $res");
if (res) {
flutterLocalNotificationsPlugin.show(
1,
"Order",
"You have new notifications",
NotificationDetails(
android: AndroidNotificationDetails('NOTIFICATION', 'New order notifications',
channelDescription: 'Shows notifications when new orders are available',
importance: Importance.max,
priority: Priority.high,
playSound: true,
category: AndroidNotificationCategory.event,
color: MyColor.kSecondary)));
}
}

Related

how to custom multi different sound of push notification in flutter

I want to set sound when push notification, but problem is app when update or install then sound is work ok and when i push local notification and change file of sound but sound notification not change follow. it still takes the old sound.
var platformChannelSpecificsAndroid = new AndroidNotificationDetails(
"fcm_default_channel",
"fcm_default_channel",
channelDescription: 'Channel to Received Push Notification',
playSound: true,
styleInformation: DefaultStyleInformation(true, true),
importance: Importance.max,
priority: Priority.high,
icon: 'launch_background',
sound: RawResourceAndroidNotificationSound(pushSound ?? ""),
);
var platformChannelSpecificsIos = new IOSNotificationDetails(
// presentSound: true
sound: pushSound ?? "");
var platformChannelSpecifics = new NotificationDetails(
android: platformChannelSpecificsAndroid,
iOS: platformChannelSpecificsIos);
new Future.delayed(Duration.zero, () {
flutterLocalNotificationsPlugin.show(
hashCode,
pushTitle,
pushText,
platformChannelSpecifics,
payload: payloadT,
);
});
I saw the same problem. I found this answer Play multiple different notification sounds from app . But it is only helpful for Kotlin

Local notification flutter :Error "Unhandled Exception: NoSuchMethodError: The method 'show' was called on null."

How i can create notification without click button?
how to initialize when opening the application a notification appears ?
String groupKey = 'com.android.example.WORK_EMAIL';
String groupChannelId = 'grouped channel id';
String groupChannelName = 'grouped channel name';
String groupChannelDescription = 'grouped channel description';
AndroidNotificationDetails firstNotificationAndroidSpecifics =
AndroidNotificationDetails(
groupChannelId, groupChannelName,
groupChannelDescription,
importance: Importance.Max,
priority: Priority.High,
groupKey: groupKey,
style: AndroidNotificationStyle.BigText,
styleInformation: BigTextStyleInformation(''),
);
final AndroidNotificationDetails android = AndroidNotificationDetails(
'ch_ID',
'Ch_Name',
'ch_Description',
priority: Priority.High,
importance: Importance.Max,
// add this line in your code
styleInformation: BigTextStyleInformation(''),
);
NotificationDetails firstNotificationPlatformSpecifics =
NotificationDetails(
firstNotificationAndroidSpecifics, null,);
flutterLocalNotificationsPlugin.show(
1, 'Confirmation ',
'Hello' , firstNotificationPlatformSpecifics);
how to launch a notification in flutter?

How to enable the "Show Notification as Pop Up" by default on android devices?

I am working on a food delivery app with Flutter. I have recently Implemented the flutter_local_notifications and the notification is working fine. But there's one problem is that the notification doesn't show as pop up by default. The "Show as pop up" option is disabled by default in the notification settings.
Is there any way that when the app is installed the "Show as pop up" option is enabled by default.
Here's my Notification Configuration Code:
void registerNotification() {
// This function registers the user for recieving push notifications.
// After registering the user, it creates a new field inside 'userForChat' Database
// The field is called : 'pushToken' which is later used on to configure Firebase Automatic Cloud Messaging
firebaseMessaging.requestNotificationPermissions();
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
print('onMessage: $message');
Platform.isAndroid
? showNotification(message['notification'])
: showNotification(message['aps']['alert']);
return;
},
onResume: (Map<String, dynamic> message) {
print('onResume: $message');
return;
},
onLaunch: (Map<String, dynamic> message) {
print('onLaunch: $message');
return;
},
);
// Token for Firebase Messaging
firebaseMessaging.getToken().then((token) {
print('token: $token');
Firestore.instance
.collection('usersForChat')
.document(currentUserId)
.updateData(
{'pushToken': token}); //Sets the firebase Token into the database
}).catchError((onError) {
setState(() {});
});
}
void configLocalNotification() {
var initializationSettingsAndroid = AndroidInitializationSettings(
'mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings);
}
void showNotification(message) async {
// This function takes the notfication message as input triggers the notification to show the message.
// The input is in a json format so you have to decode the json with dart:convert.
// IMPORTANT: Specify the Application package name according to the OS.
//For Android, Use the android app package name from firebase
//For iOS, Use the iOS app package name from firebase
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
// add your apps package name for each OS(Android:iOS)
Platform.isAndroid
? 'com.jexmovers.app' //Update the package name to your app's package names
: 'com.jexmovers.ios', //Update the package name to your app's package names
'JexMovers Chat',
'App that lets you contact with your food delivery person',
playSound: true,
enableVibration: true,
importance: Importance.Max,
priority: Priority.Max,
visibility: NotificationVisibility.Public,
enableLights: true,
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
print(message);
print(message['body'].toString());
print(json.encode(message));
await flutterLocalNotificationsPlugin.show(
0,
message['title'].toString(),
message['body'].toString(),
platformChannelSpecifics,
payload: json.encode(message),
);
}

Icon issues localNotificationsPlugin, how to add app Icon the right way

I have implemented local push notifications in flutter app. This plugin was working smoothly at first. The issues came when I had run flutter clean and also uninstalling the app on android Emulator to do a clean install with flutter run. After doing so the app crashes on startup.
When run the app in debugging mode, it is showing that the error is happening on await localNotificationsPlugin.initialize. Debugger showing statement below.
Exception has occurred.
PlatformException (PlatformException(INVALID_ICON, The resource ic_launcher could not be found. Please make sure it has been added as a drawable resource to your Android head project., null))
Code below is showing how I have implemented the localNotificationsPlugin.
FlutterLocalNotificationsPlugin localNotificationsPlugin =
FlutterLocalNotificationsPlugin();
initializeNotifications() async {
var initAndroid = AndroidInitializationSettings('ic_launcher');
var initIOS = IOSInitializationSettings();
var initSettings = InitializationSettings(initAndroid, initIOS);
await localNotificationsPlugin.initialize(
initSettings,
onSelectNotification: gotToNotificationsPage,
);
}
#override
void initState() {
super.initState();
initializeNotifications();
showNotification();
}
Future singleNotification(
DateTime datetime, String message, String subtext, int hashcode,
{String sound}) async {
var androidChannel = AndroidNotificationDetails(
'channel-id',
'channel-name',
'channel-description',
importance: Importance.Max,
priority: Priority.Max,
);
var iosChannel = IOSNotificationDetails();
var platformChannel = NotificationDetails(androidChannel, iosChannel);
localNotificationsPlugin.schedule(
hashcode, message, subtext, datetime, platformChannel,
payload: hashcode.toString());
}
showNotification() async {
DateTime now = DateTime.now().toUtc().add(
Duration(seconds: 5),
);
await singleNotification(
now,
'Notification',
'This is a notification',
98123871,
);
}
Future gotToNotificationsPage(String payload) {
return Navigator.pushNamed(context, '/notifications');
}
Note the problem is on await localNotificationsPlugin.initialize I'm failing to assign app Icon properly. Thank you.
To set a custom icon, you can add an app_icon.png inside android/app/src/res/drawable, then initialize it with
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('app_icon');`
Otherwise, if you'd like to use the default app icon, you can set the app icon on AndroidInitializationSettings with #mipmap/ic_launcher
If you're unsure on where to start, you can try out the sample provided by the plugin on GitHub.

flutterLocalNotificationsPlugin.show

My flutter app, show this notification when FCM is triggered.
await flutterLocalNotificationsPlugin.show(
0, "my app. Alert", "Alert text from App", platform
);
Is there any way to show a image in the notification bar and not only the text?
Something like:
await flutterLocalNotificationsPlugin.show(
0, "my app. Alert", "Alert text from App","url: myimage.com/sample.jpg", platform
);
Thanks
If you are using the flutter_local_notifications plugin, then you can do something like this for android:
Future<void> _showBigPictureNotification() async {
var largeIconPath = await _downloadAndSaveImage(
'http://via.placeholder.com/48x48', 'largeIcon');
var bigPicturePath = await _downloadAndSaveImage(
'http://via.placeholder.com/400x800', 'bigPicture');
var bigPictureStyleInformation = BigPictureStyleInformation(
bigPicturePath, BitmapSource.FilePath,
largeIcon: largeIconPath,
largeIconBitmapSource: BitmapSource.FilePath,
contentTitle: 'overridden <b>big</b> content title',
htmlFormatContentTitle: true,
summaryText: 'summary <i>text</i>',
htmlFormatSummaryText: true);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'big text channel id',
'big text channel name',
'big text channel description',
style: AndroidNotificationStyle.BigPicture,
styleInformation: bigPictureStyleInformation);
var platformChannelSpecifics =
NotificationDetails(androidPlatformChannelSpecifics, null);
await flutterLocalNotificationsPlugin.show(
0, 'big text title', 'silent body', platformChannelSpecifics);
}
For more such examples, please refer the official example provided by the plugin developer, here.

Categories

Resources