I am working on a iOS version of Xamarin application (android was built by another person). I have used Plugin.FirebasePushNotifications plugin and have successfully set up the apns from Firebase console. The response looks something like this:
2020-09-28 12:50:57.566 Project.iOS[16900:2364597] {
aps = {
alert = {
body = "This is the body of the notitification";
title = "Testing Notification";
};
"mutable-content" = 1;
sound = default;
};
"gcm.message_id" = 1601286657133844;
"gcm.notification.sound2" = default;
"google.c.sender.id" = 633381035766;
}
The notifications successfully arrives on the device and it works perfectly in foreground/background/app killed.
However, when I use different server with different protocol(?) I receive this type of message:
2020-09-28 12:51:30.944 SycretBeauty.iOS[16900:2364597] {
Body = "\U0422\U0415\U0421\U0422 8";
Title = "Title";
aps = {
"content-available" = 1;
};
"gcm.message_id" = 1601286690545984;
}
The id is the same and I receive it ok in VS console. However, the notification doesn't pop up on the screen. What should I do to see the notification popping up on the screen? I can't change the API and Android is already all set up working with that type of response structure...
(and I don't even know why "TEST 8" shows in UNICODE characters...)
I have solved the issue by downstreaming through Postman.
Url: https://fcm.googleapis.com/fcm/send
Headers(2):
ContentType - application/json
Authorization - <your server key from firebase>
Body:
{ "to":"d8bEmMpQJE6EuEYCG4COKq:APA91bG7YCDT7AyyJGS3j5bnpwVrbvSgdrjuUcatjOBLSkKaGpa2xZP7YDhzMAEMYfLDDp7gTgzUzhx-vs4nvr_n3yJQ6FdU9m0sxxw-stzHIxtuvXEPSXNHGy_2yxWBxGLn0IVktsil",
"notification" : {
"Body" : "Notification Body",
"Title" : "Notification Title",
"content_available" : true,
"priority" : "high"
}
}
The notification arrives after I use correct syntax for "body" and "title" all the time.
Related
I use Firebase for notification in my Android application and try create custom sound for notification in background. Client app doesn't handle notifications, only android system. Notifications are sent from backend. Json structure:
{
"message": {
"token": "e1IMKJe...",
"notification": {
"title": "Test",
"body": "Test message from server"
},
"android": {
"notification": {
"sound": "sound_base_notification",
"channel_id":"test_chanel_id"
}
}
}
}
In method onMessageReceived, I obtained response like this:
Bundle[{google.delivered_priority=normal, google.sent_time=1596444752253, gcm.notification.android_channel_id=chanel_id_test,
google.ttl=23746652,
google.original_priority=normal,
gcm.notification.e=1,
gcm.notification.sound=default,
gcm.notification.title=Test,
from=763552563,
gcm.notification.sound2=sound_base_notification,
google.message_id=0:1596...,
gcm.notification.body=Test message from server,
google.c.a.e=1,
google.c.sender.id=29852264618,
collapse_key=com.test}]
Could you help me understand where does the gcm.notification.sound2 come from although in json push exsist onle single key sound?
Note: Was testing on Android 10
I've searched everywhere and tried many solutions with no luck. I am using an API to send notifications to my app ( Android / IOS) with a custom sound file that is already included in my app files. the sound works fine for IOS even if the app is closed but it doesn't work for Android until the app is working on the background.
here is the JSON which I use
{
to = deviceId,
priority = "high",
content_available = true,
notification = new
{
body = englishMessage,
title = title,
badge = 1,
content_available = true
},
android = new
{
ttl="86400s",
priority= "high",
notification = new
{
sound = SoundFileName,
},
},
apns = new
{
payload = new
{
aps = new
{
sound = SoundFileName,
content_available = true,
badge = 1,
},
},
customKey = "test app",
}
}
When your app is in the foreground the notification is manually generated by you which means you need to manually add this sound to your notification, so what you do is something like
var soundUri = Android.Net.Uri.Parse(pathToPushSound);
And then in the notification manager add the following method
var notiManager= Notification.Builder(context)
.SetSound(soundUri) ...
I try use FCM to send notification.
I try 2 methods to send notification,
I send notification (FCM) via Firebase Console (Success, push notification appear on top screen)
I send notification via https://fcm.googleapis.com/fcm/send. Here my setup :
let title = "My Title";
let msg = "Test Notification";
let header = {
headers: {
'Authorization': 'key=' + serverKey,
'Content-Type': 'application/json'
},
};
let body = {
"registration_ids": clientToken,
"data": {
'body': msg,
'title': title,
'link': '-',
'click_action': 'OPEN_MAIN_ACTIVITY',
}
}
My Question is The first method work fine (notification appear). But
why when i send FCM with the second method, on Android not appear the
push notification? Can you find what mistake of the code ?
I have a problem regarding my SNS Push Notifications. I have the following lambda code:
db.scan(params, function(err, data) {
if (err) {
console.log(err); // an error occurred
}
else {
data.Items.forEach(function(record) {
var receiverID = record.userDeviceToken.S;
var message = "You have a new invitation to the event";
var topic = "Friend's invitation";
var eventText = JSON.stringify(event);
console.log("Received event:", eventText);
var sns = new AWS.SNS();
var params = {
Message: message,
Subject: "Friend's invitation",
TargetArn: receiverID,
};
sns.publish(params, function(err, data) {
if (err) {
console.log('Failed to publish SNS message');
context.fail(err);
}
else {
console.log('SNS message published successfully');
context.succeed(data);
}
});
});
//context.succeed(data.Items); // data.Items
}
});
};
Now my goal is to get the "Subject" or "topic" sometimes, if it is possible. I cannot find it in documentation, and I need it to customize my notification title depending on the push message sent (I have few functions).
When I used sample amazon app I found this cound in Push Listener Service:
public static String getMessage(Bundle data) {
// If a push notification is sent as plain text, then the message appears in "default".
// Otherwise it's in the "message" for JSON format.
return data.containsKey("default") ? data.getString("default") : data.getString(
"message", "");
}
This works, but the "data" itself has the following data:
Bundle[{google.sent_time=1480364966070, google.message_id=0:1480364966079787%22269524f9fd7ecd, default=You have a new invitation to the event, collapse_key=do_not_collapse}]
Therefore, it is just providing some internal data and the "message" itself. I cannot access the topic.
My question is: how to get other variables in the Android code so I can use them further on? Can I add custom variables by myself through data bundle?
I have notifications in JSON format. I just wonder, whether the only way is to put the data I want in JSON format inside the message, and then read the message accordingly, or maybe I can attach the required data from lambda function to the push notification already?
I am new to Firebase and the main reason I adapted to it from my old MySql DB is the ability to send push notification and dynamic links. I have been trying for the past two days to send notification to a group of people who have subscribed to a topic from my node.js script. The script always returns InternalServerError. I am able to send notification from the Firebase console but that is not good enough for my app as I need to implement dynamic notification (i.e. triggered by one users action).
So far I did not understand what was in the official docs and tried following a tutorial I found and I am currently here
app.get('/push',function(req,res){
/*var title = req.params.title;
var body = req.params.body;*/
// var confName = req.params.name;
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
to: '/topics/ilisten',
// collapse_key: 'your_collapse_key',
notification: {
title: 'This is Title',
body: 'This is body'
},
data: { //you can send only notification or only data(or include both)
my_key: 'Conf Name here'
}
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!"+err);
} else {
console.log("Successfully sent with response: ", response);
}
});
})
My first question is what should I do in the to field so that all the users in my app reciece the notification.
I would also like to take a look at correct and complete implementation of this concept with android code. If anyone has such code please share it here as it would help the future Firebase users who cannot understand the official docs like me.
Following is one approach using node-gcm (https://github.com/ToothlessGear/node-gcm)
var gcm = require('node-gcm');
var sender = new gcm.Sender(<sender_key>);
var message = new gcm.Message();
message.addNotification('title', title);
message.addNotification('body', body);
sender.send(message, { topic: "/topics/" + topic }, function (err, response) {
if (err) console.error(err);
else console.log(response);
});