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
Related
I want to read the date field from payload of this push notification but the api doesn't seem to work :(
I'm now from hms Huawei, i have read this tutorial:
HMS-Plugin-Guides-V1
all part is completed except d point, -> error of overwriting.
When i send a notification, and i push on it. All ok my app will open. But i can't read notification body.
In the log i see the notification service start -> take token and immediately kill itself... i don't understand where is problem.
Notify JSON
{
"validate_only": false,
"message": {
"notification": {
"title": "Notifica simpatica",
"body": "Io sono il body della notifica simpatica",
"notify_icon": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png"
},
"data": "{'param1':'value1','param2':'value2'}",
"android": {
"collapse_key": -1,
"urgency": "NORMAL",
"category": "PLAY_VOICE",
"ttl": "1448s",
"fast_app_target": 1,
"notification": {
"click_action": {
"type": 1,
"intent": "intent://eccc_ecc"
}
}
},
"token":-xxxxx"
]
}
}
My app code:
const App = () => {
HmsPushEvent.onTokenReceived(result => {
console.log('Push token', result.token);
});
HmsPushEvent.onRemoteMessageReceived(event => {
console.log('Data message received');
const RNRemoteMessageObj = new RNRemoteMessage(event.msg);
const msg = RNRemoteMessageObj.parseMsgAllAttribute(event.msg);
console.log('Data message received : ' + msg);
});
return (
<SafeAreaView>
<Text>Testing Text</Text>
</SafeAreaView>
);
};
Manifest (only application section, other line is standard for any android app):
<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true" />
</application>
this is 'condensed' log:
16:23:53.989 HMSSDK_HmsMessageService: start to bind
16:23:54.032 HMSSDK_HmsMessageService: handle message start
16:23:54.036 HMSSDK_HmsMessageService: onNewToken
16:23:54.043 HMSSDK_HmsMessageService: doOnNewToken:transactionId = null , internalCode = 0,subjectId:null,proxyType:null
16:23:54.046 HMSSDK_HmsMessageService: Apply token OnNewToken, subId: null
16:23:54.179 HMSSDK_HmsMessageService: onNewToken to host app.
16:23:54.215 HMSSDK_HmsMessageService: onNewToken to host app with bundle.
16:23:54.222 HMSSDK_HmsMessageService: start to destroy
You are trying to send a Notification messages, but onRemoteMessageReceived is used to receive a data message, so you cannot read the date field.
User-defined fields of notification messages are transferred to the app when a user clicks a message and need to be received through the HmsPushEvent.onNotificationOpenedApp(callback).
For more details, pls kindly refer to this interface documents.
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.
We are planning on migrating to using topics through FCM for our application.
I have done some tests and have noticed a weird behaviour (looks very much like a bug).
When receiving a new token for the same InstanceID the https://iid.googleapis.com/iid/info/ endpoint still shows previously active topic subscriptions for this instance id.
But notifications sent to this topic do not arrive on the device.
These are the steps I took:
Get a token in the Android SDK
FirebaseInstanceId.getInstance().getToken(projectId, scope) => ABC:123
Subscribe to a topic in the Android SDK
FirebaseMessaging.getInstance().subscribeToTopic(topicName)
Verify the topic was subscribed to using the API call: https://iid.googleapis.com/iid/info/ABC:123?details=true
{
"applicationVersion": "1",
"connectDate": "2019-02-18",
"attestStatus": "UNKNOWN",
"application": "com.foo.bar",
"scope": "*",
"authorizedEntity": "12345",
"rel": {
"topics": {
"topicName": {
"addDate": "2019-02-18"
}
}
},
"connectionType": "WIFI",
"appSigner": "XXXXXXX",
"platform": "ANDROID"
}
Send a notification to the topic => notification arrives
Delete the token in the Android SDK
FirebaseInstanceId.getInstance().deleteToken(projectId, scope)
Get a new token in the Android SDK
FirebaseInstanceId.getInstance().getToken(projectId, scope) => ABC:456
Verify the topic was subscribed to using the API call: https://iid.googleapis.com/iid/info/ABC:456?details=true
{
"applicationVersion": "1",
"connectDate": "2019-02-18",
"attestStatus": "UNKNOWN",
"application": "com.foo.bar",
"scope": "*",
"authorizedEntity": "12345",
"rel": {
"topics": {
"topicName": {
"addDate": "2019-02-18"
}
}
},
"connectionType": "WIFI",
"appSigner": "XXXXXXX",
"platform": "ANDROID"
}
Just to verify this is the new response for the deleted token.
https://iid.googleapis.com/iid/info/ABC:123?details=true
{ "error": "No information found about this instance id." }
Send a notification to the topic => notification does not arrive!
This behavior does not restore. (We waited a full day).
Why does the info endpoint show that the new token was subscribed to the topic, but in reality is not registered at all?
The only fix seems to be re-subscribing the new token on the topic.
Thanks in advance.
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 am doing sample PoC using GCM. I send the registration request to gcm server from my device and got the registration id for successful registration. I stored all the registration id in my app server database. I sent the data only one time to GCM from my app server to all my registration id. But, the OnMessage() method of GcmBaseIntentService called multiple time.
here is GCM response to my appserver when i am sending data
{
"multicast_id": 5986417894970376000,
"success": 7,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1355230384617663%9fa953f8f9fd7ecd"
},
{
"message_id": "0:1355230384617914%9fa953f8f9fd7ecd"
},
{
"message_id": "0:1355230384617911%9fa953f8f9fd7ecd"
},
{
"message_id": "0:1355230384617987%9fa953f8f9fd7ecd"
},
{
"message_id": "0:1355230384617909%9fa953f8f9fd7ecd"
},
{
"message_id": "0:1355230384617985%9fa953f8f9fd7ecd"
},
{
"message_id": "0:1355230384618032%9fa953f8f9fd7ecd"
}
]
}
I am doing some time taking task in my onMessage() method using AsynTask, Due to this multiple calls multiple thread getting created.
Please advice me on this issue.
The problem with my server side code. Single registration id added multiple times in devices list of my payload data.