{
"to": "XXXX",
"notification": {
"title": "ASAP Alert",
"body": "Please open your app"
},
"data": {
"screen": "/Nexpage1",
"sound": "alarm",
"click_action": "FLUTTER_NOTIFICATION_CLICK"
}
}
Above is my payload for the push notification. I have insert the alarm.mp3 file inside the raw folder, however it still does not give me the alarm sound, i have try for alarm.mp3 also, is there anything wrong with the json? of it because of the code on my dart file?
Reading this it seems that it should be manage automatically (if you didn't use a notification builder) on Android but you have to specify the .mp3 extension too and put it inside notification field and not data one..
"sound": "alarm.mp3"
iOS behaves very differently under the hood but you can use a custom sound by setting the sound: field in the notification payload too. Anyway .mp3 is not a valid APN notification file format, and you need to specify also the file extention.
"sound": "filename.caf"
Follow Apple documentation in order to forge your custom sound file for your app.
mp3 is not a valid format
Preparing Custom Alert Sounds
Local and remote notifications can specify custom alert sounds to be
played when the notification is delivered. You can package the audio
data in an aiff, wav, or caf file. Because they are played by the
system-sound facility, custom sounds must be in one of the following
audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
Place custom sound files in your app bundle or in the
Library/Sounds folder of your app’s container directory. Custom
sounds must be under 30 seconds when played. If a custom sound is
over that limit, the default system sound is played instead.
You can use the afconvert tool to convert sounds. For example, to
convert the 16-bit linear PCM system sound Submarine.aiff to IMA4
audio in a CAF file, use the following command in the Terminal app:
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
For exampole to convert your mp3 file in a caf file you could type in terminal:
afconvert -f caff -d LEI16 alarm.mp3 alarm.caf
Read this doc in order to have a deep inside of all generic and specific notifciation payload fields.
UPDATE
I've tested the Android part and I can confirm that putting your .mp3 file in res/raw/ folder the sound is played as documented and expected.
That's my notification payload:
{
"to" : "my_device_token",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Test Notification body for custom sound {{datestamp}}",
"title": "Custom sound alert.mp3",
"sound": "alert.mp3"
}
}
I've tested also the iOS version after converting .mp3 file to .caf file in that way:
afconvert -f caff -d LEI16 alert.mp3 alert.caf
the same json payload with the different filename works:
{
"to" : "my_device_token",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Test Notification body for custom sound {{datestamp}}",
"title": "Custom sound alert.mp3",
"sound": "alert.caf"
}
}
Remember to add the file in your main bundle.
That works if the app is terminated or in background.
If you want to show an alert and play a sound when the app is in foreground you have to manage it on onMessage event like someone already have told you here, or you can use a platform-channel here to build your own notification with a Notification.Builder on Android and a UNNotificationCenter on iOS (for example).
UPDATE
This issue has been solved. See here the official comment:
Hey all 👋
As part of our roadmap (#2582) we've just shipped a complete rework of
the firebase_messaging plugin that aims to solve this and many other
issues.
If you can, please try out the dev release (see the migration guide
for upgrading and for changes) and if you have any feedback then join
in the discussion here.
Given the scope of the rework I'm going to go ahead and close this
issue in favor of trying out the latest plugin.
Thanks everyone 🤓
ShadowSheep did a good job at answering this question, but there's one thing I want to clarify for trying to get the iOS sounds to work.
You have to add the sound into XCode (which is where ShadowSheep speaks of including the asset inside of the main bundle). You can just drag and drop the audio file (in .caf or other supported format mentioned above) into the root directory (usually called Runner for Flutter) in XCode:
If you have done this and follow the setup described in the above question/answer, you should be in business.
For me I am using the flutter_local_notifications to create the notification channel.
include this function (may create multiple notification channel)
Future<void> _createNotificationChannel(String id, String name,
String description, String sound) async {
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
var androidNotificationChannel = AndroidNotificationChannel(
id,
name,
description,
sound: RawResourceAndroidNotificationSound(sound),
playSound: true,
);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(androidNotificationChannel);}
call the function in initState: (this created 2 notification channel)
_createNotificationChannel("channel_id_1", "channel_name", "description", "alert");
_createNotificationChannel("channel_id_2", "channel_name", "description", "alarm");
Remember to save the file of alert and alarm in the res/raw in file format of .mp3.
with this payload :
{
"notification": {
"title": "My First Notification",
"body": "Hello, I'm push notification"
},
"data": {
"title": "My First Notification"
},
"android": {
"notification": {
"channel_id": "channel_id_1"
}
},
"to": "device_token"}
For the people who try to make custom sound for both android and ios good guide here:
For iOS:
To add a custom sound for iOS, add the audio clip for iOS to your
project's App_Resources/iOS/ directory (iOS only accepts .wav, .aiff,
and .caf extensions).
For Android:
First, add the audio clip to your project's
App_Resources/Android/src/main/res/raw/ directory ((Android only
accepts .wav, .mp3 and .ogg extensions).
So we can use .wav file in order to use custom sound available for both platform:
"notification": {
"body": "Test notification",
"title": "Test Test Test",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"sound": "your_custom_sound.wav"
"android_channel_id": "channel_id_youcreated",
},
'to':
"",
},
after try this solution in Android I still can't change with custom sound. You need .ogg file type to resolve this issue. After changed to .ogg file type, I can change with custom sound. Thanks.
Related
I'm trying to plan a rewrite of my website and I want to make it that I can login passwordless with just Windows Hello, TouchID, or FaceID using WebAuthn. All the examples online have a whole popup situation but I want it done like my mockup. I also want my website to detect the default biometric and have the biometric icon change to the icon representing the default one, for example, face icon for FaceID. This website will be done using python-flask, ReactJS, MySQL, CSS, and HTML.
There's a few different points to hit on here -
Pop-up/Modal
We'll start with this one. Unfortunately the pop-ups that appear during the WebAuthn ceremony are part of the browsers implementation. Every time the get()/create() methods are called the pop-ups will be invoked. There is some work coming out from Google/Apple in their passkey implementation where this will look more like an "autofill" experience, but you will still be required to use their pop-ups.
Defaulting to Windows Hello, Touch ID, etc..
I'll start by suggesting that you shouldn't constrain your users to only the platform authenticators. Security keys still play a big role in WebAuthn and work really well for signing in across devices. Relying on platform authenticators could limit your users to the device they initially registered with, or limit users who don't have a biometric sensor on their device.
With that being said, you can explicitly invoke the use of only platform authenticators using the PublicKeyCreationOptions. In the property authenticatorSelection there is a field authenticatorAttachment. If you set this field to "platform" then your platform authenticator will be invoked (if one is available).
Here's an example of the request sent by the relying party (note the property authenticatorSelection towards the bottom):
{
"publicKey": {
"rp": {
"name": "Example Inc",
"id": "example.com/"
},
"user": {
"name": "user",
"displayName": "user",
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"challenge": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"pubKeyCredParams": [***],
"excludeCredentials": [***],
"authenticatorSelection": {
"authenticatorAttachment": "platform"
"residentKey": "preferred",
"userVerification": "preferred"
},
"attestation": "direct",
"extensions": {}
}
}
Detecting default biometric
I have a React example here. Some things to note on this approach:
There are more elegant and accurate ways of determining what platform the user is on. This snippet will work a majority of the time, but there is a lot of assumption happening based only on the detected OS
There's no icons included, I would suggest adding an imgSrc field to the enums that includes a link to the source image
Hope this helps.
I Want to know how to open a new screen when the notification is tapped. In my case, if I click on it, it do nothing... I want that (depending of the notification) it opens the app and opens a new given screen
This is the json I'm sending now:
'{"notification": {"body": "${body}", "title": "${title}", "click_action": "FLUTTER_NOTIFICATION_CLICK"}, "priority": "high", "to": "MYTOPIC"}';
You can use this library to generate named routes and then when the notification is clicked your onLaunch() method is executed wherein you can extract the path from the deeplink and pass it to the navigator.
Now lets say you have 2 screens users screen and user profile screen. You'll have two routes defined in your router class.
MaterialRoute(page: UsersScreen, path : '/users'),
MaterialRoute(page: UserProfileScreen, path : '/users/:userId?'),
In the notification data payload you can pass the data link as /users or /users/:userId? , extract the data on onLaunch triggered from terminated state and pass it to your navigator. You can have a look at their example to get a better understanding of the named routes.
Actually today I received a customer report.
The push notification do not arrive at the devices.
After some research I figured out that the negative topic condition I use to send notifications to all devices, stop working.
One week ago the sending worked well with the same condotions.
I uses Postman for developing the requests.
I use the Rest API with "send" endpoint.
https://fcm.googleapis.com/fcm/send
here is my payload:
{
"condition":"!('nonExistingTopic' in topics)",
"data": {
"notification_foreground": true,
"link": "https://www.google.com"
},
"notification": {
"click_action": "FCM_PLUGIN_ACTIVITY",
"title": "notification title",
"body": "notification message"
}
}
I received an "ok"-status from Firebase ad the "message_id", but no message was send. So obviously the condition do not fit to any of the devices.
When I use the field "registration_ids" with a fcm token of my device I receive the notification.
I allready tried to find some kind of Update changes in firebase changelogs, that maybe changed the behavior of the condition field. But I did not find anything.
Does anybody have the same problems?
Any ideas for a work around!
Thank You!
I have the same problem here, as temporary solution I have to send notifications thought Firebase Console (because I use it just for communication with users).
Also I will launch a new update that now it is registering to a topic called "general" when start up.
I didn't figure out how to send to all users using negative topic condition. It stopped working about 10 days ago.
Meanwhile i found a solution for this problem.
I only use the condition-field for really existing topics.
"condition" = "'sport' in topics"
To send a message to all devices you can use the "to" parameter with the value "/topics/all", instead of the "negativ" condition.
{
"notification": {
"title": "myTitle",
"body": "myTeaser"
},
"to": "/topics/all",
"data": {
"myCustomDataField": "myFieldValue"
}
}
In my unity project I want play custom sound when I get firebase cloud message, not system default sound.
So after I followed other answers my message looks like,
{
"to": "some_key",
"notification": {
"title": "Title",
"android_channel_id": "2",
"body": "Body",
"sound": "custom_sound.wav"
}
}
and I placed custom_sound.wav in Asset/Plugins/Android/res/raw. When I unzip my .apk, I can find my sound file is in right location.
But it keeps playing system default sound. Even after I remove sound field. Is there any other thing should I check?
First: a quick tip when debugging. If you select "Export Project", you can open the generated Gradle project with Android Studio:
Occasionally you have to update the gradle wrapper, but it helps a ton debug things like "is my sound file in res/raw" without having to decompress your APK and poke around.
I think that the issue you're running into now is that sounds are now associated with NotificationChannels (as of Android O) rather than individual notifications, as noted by this StackOverflow post expressing a similar issue. Since this isn't exposed via the Unity SDK.
Fortunately, you can add a channel with Unity.Notifications.Android.
It should be as simple as creating a new
public AndroidNotificationChannel(string id, string title, string description, Importance importance)
with your id set to "2" (to match your sample notification above. Since this is a string, I would recommend giving this a better name :D).
Then you can call RegisterNotificationChannel with that channel you create as your parameter.
For example, to get your notification above to work, I believe you can write:
var notificationChannel = new NotificationChannel("2", "Channel 2 (working title)", "This is the 2nd channel", Importance.Default);
AndroidNotificationCenter.RegisterNotificationChannel(notificationChannel);
Let me know if this helps!
--Patrick
In the Notifications section in the Settings app, my app only has "Badges" listed under it where it should have "Badges, Sounds, Banners".
Due to this I don't get "notified" when a new notification comes in, i.e. no banner, no sound, no vibrations. The notification shows up in the notifications tray and on the lock screen and the badge number updates, but there are no alerts.
Any ideas how to fix this?
My config.push.json looks like this:
{
"apn": {
"passphrase": "passphrase",
"key": "PushChatKey.pem",
"cert": "PushChatCert.pem"
},
"production":false,
"badge": true,
"sound": true,
"alert": true,
"vibrate": true
}
And I send notifications like this:
`Push.send({
from: 'Test',
title: 'Hello',text: 'World',
badge: 4,
query: {},
sound: 'default'
});`
(Similar to iOS push notifications only showing badges. need sounds and banners too but using different framework.)
I was able to solve this using the Push.Configure({}) setup on both server and client.
Server code:
Push.Configure({
apn:{
passphrase:'password',
certData: Assets.getText('enter certificate pem file name'),
keyData: Assets.getText('enter key pem file name')
},
production: false //or true if production
});
Client code (including the alert:true is what did the trick for me):
Push.Configure({
badge:true,
sound:true,
alert:true
});