Flutter FCM custom sound not working notification - flutter

var result = await FlutterNotificationChannel
.registerNotificationChannel(
description: 'My test channel',
id: 'com.softmaestri.testchannel',
importance: NotificationImportance.IMPORTANCE_HIGH,
name: 'afthal',
);
print('Result: $result');
},
this is how i create my channel and
{
"to":"MY_FCM_TOKEN",
"notification":{
"body":"test fawsan",
"title":"fawsan title",
"sound":"beeb.mp3",
"android_channel_id":"afthal"
}
}
it sends notification and it does not use my sound which is in res/raw folder (Project\android\app\src\main\res\raw)

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,
)
);
}

Add button to notification in flutter_foreground_task

how add button named "Disconnect" in AndroidNotificationOptions ?
my simple code is here .
const AndroidNotificationOptions(
channelId: 'parameter_channel',
channelName: 'Parameters',
channelDescription: 'This notification appears when the reading begaz params running.',
channelImportance: NotificationChannelImportance.LOW,
priority: NotificationPriority.LOW,
visibility: NotificationVisibility.VISIBILITY_PRIVATE,
playSound: false,
enableVibration: false,
iconData: NotificationIconData(
resType: ResourceType.mipmap,
resPrefix: ResourcePrefix.ic,
name: 'launcher',
),
),
in here im using flutter_foreground_task.
If you look at the documentation you will see an example, but in your case should be like this:
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'notification_channel_id',
channelName: 'Foreground Notification',
channelDescription: 'This notification appears when the foreground service is running.',
channelImportance: NotificationChannelImportance.LOW,
priority: NotificationPriority.LOW,
iconData: const NotificationIconData(
resType: ResourceType.mipmap,
resPrefix: ResourcePrefix.ic,
name: 'launcher',
),
buttons: [
const NotificationButton(id: 'disconnect', text: 'Disconnect'),
],
),
The clicks events should be handled in the TaskHandler, like this:
class MyTaskHandler extends TaskHandler{
...
#override
void onButtonPressed(String id) {
// Called when the notification button on the Android platform is pressed.
if(id == 'disconnect'){
//stop the foreground task
//do the disconnect
}
}
...
}

ionic react local notifications with capacitor not working

I am trying to implement local notifications using capacitor.
first I installed plugin using below commands,
npm install #ionic-native/local-notifications
npm install cordova-plugin-local-notification
Then in my .js file, I did add below code
import { Plugins } from '#capacitor/core';
And
scheduleNotification = () => {
Plugins.LocalNotifications.schedule({
notifications: [
{
title: "Title",
body: "Body",
id: 1,
schedule: { at: new Date(Date.now() + 1000 * 5) },
sound: null,
attachments: null,
actionTypeId: "",
extra: null
}
]
});
console.log('scheduled notifications');
}
I tried everything, but I can't see any local notification on my iPhone 6s running iOS 12.
When I check Xcode logs, I can see Scheduled notification with id 1.
cordova-plugin-badge (0.8.8)
cordova-plugin-device (2.0.3)
cordova-plugin-local-notification (0.9.0-beta.2)
I had the same issue, I set my notification id with an UUID but it did not work. I solved it in setting my notification id with new Date().getTime().
It was issue regarding id pass in your result.
PushNotifications.addListener('pushNotificationReceived',
async (notification: any) => {
console.log(notification);
const notifs = await LocalNotifications.schedule({
notifications: [
{
title: notification.title,
body: notification.body,
id: new Date().getTime(),
schedule: { at: new Date(Date.now() + 1000 * 5) },
sound: this.platform.is("android")
? "file://sound.mp3"
: "file://beep.caf",
attachments: null,
actionTypeId: "",
extra: notification
}
]
});
}
);
For the ios, I think, it is not supported yet.
For android, try to request permission.

No vibrate in flutter notifications

I am using firebase cloud functions to send a notification to a particular user. This is the payload that I am sending from the functions.
var payload = {
notification: {
sound: "default",
color: "#ff3296fa",
vibrate: "300",
priority: 'high',
notificationType: "52",
title: titleToBeShown,
body: message['message'],
icon: 'ic_launcher',
},
data: {
click_action: 'FLUTTER_NOTIFICATION_CLICK',
channelId: channelID,
channelName: channelName,
channelType: channelType
},
};
I am using firebase_messaging (flutter package: https://pub.dartlang.org/packages/firebase_messaging) to receive the notifications and I have written the codes for onMessage, onLaunch and onResume methods.
So when I send a message using Admin SDK admin.messaging().sendToDevice(token, payload), it sends it without vibration and sound. How can I add vibration and sound to it? Right now, it feels like a silent notification then. Which will easily be ignored by the users. Both in android and ios, its the same problem.
The sound field does not go in the notification object. It belongs in the android and apns objects. Your payload should look like this:
var payload = {
data: {
channelId: channelID,
channelName: channelName,
channelType: channelType
},
android: {
priority: 'high',
notification: {
title: titleToBeShown,
body: message['message'],
icon: 'ic_launcher',
sound: 'default',
color: '#ff3296fa',
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
// Not sure what this is supposed to be, but not a valid parameter
notificationType: '52',
},
},
apns: { ... }
};
I've filled in the Android fields, but I'm not familiar with APNS payloads. Check out the FCM documentation here for more details and you can see the available payload options for APNS here.

Backend service for ionic push

I have implemented ionic push notifications using pushwoosh. But there I use the dashboard which has provided by pushwoosh to send push notifications. I wanted to send push notifications using a back end which has created by my self. How do I do that?
i am working on ionic-framework and also using push notification to sent notification via REST API using node-gcm its working fine.
sample code
(function() {
function execute(rqst, q, fwk) {
var gcm = require('node-gcm');
var message = new gcm.Message();
message.timeToLive = 3000;
message.addData({
title: 'Push Notification Sample',
body: 'Abnormal data access',
icon: 'ic_launcher',
message: '"\u270C Peace, Love \u2764 and PhoneGap \u2706!'
});
message.addNotification({
title: 'Push Notification Sample',
body: 'Abnormal data access',
icon: 'ic_launcher',
message: 'hey , how are you?'
});
/* message.addData('message', "\u270C Peace, Love \u2764 and PhoneGap \u2706!");
message.addData('title', 'Push Notification Sample');
message.addData('msgcnt', '3');*/
// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
// Set up the sender with you API key
var sender = new gcm.Sender('xxxxxxxxxxxxxxxxx-hK5wE');
// Add the registration IDs of the devices you want to send to
var registrationIds = [];
registrationIds.push('APA91bEWB6-xcrfrfrffr-LqyMohLP4T-XuydQgt44Q6Acw5kmVDWvAaOsm1CriASm02SyBceZ2NBWF4FIES7grcPeY5v4fLQme2UqhRteeWRdD_Ma25QMGESOGAyw_Uhgg_EjkTl-');
// Send the message
// ... trying only once sendNoRetry
sender.send(message, {
registrationIds: registrationIds
}, function(err, result) {
if (err) {
console.error(err);
q.resolve({
status: 200,
data: {
data: err,
code: 1
}
});
} else {
console.log(result);
q.resolve({
status: 200,
data: result
});
}
});
}
return exports.execute = execute;
})();