I have an android application that uses FCM to get notifications.
I'm using this versions:
implementation "com.google.firebase:firebase-analytics-ktx:17.4.3"
implementation "com.google.firebase:firebase-inappmessaging-display-ktx:19.0.7"
implementation "com.google.firebase:firebase-messaging:20.2.0"
The problem that I've encountered recently is that I tried to send push notification with my own backend server via REST API call. I noticed that for every single api call, android devices get notifications twice.
So I've checked this Question: Firebase send push notification twice and I noticed that like Tom Bevelander's answer, I have a third party lib that uses GCM behind and when I removed that lib from project, problem fixed.
So I have to force my users to update the application. but I don't really want this approach. Something that I saw is that on previous version (GCM included app) when I'm testing push notification with Firebase Panel itself, everything works fine and devices get single notification. but with api call, devices get duplicate notifs. What is the difference between this approaches? How can I find out whats happening behind the FirebasePanel? So that I call same api that panel uses itself?
The endpoints that I've tested is this:
https://fcm.googleapis.com/fcm/send
and this:
https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
brother may shore the device token is maybe duplicate like two users sign in from the same device and both user device token is same and server through a notification on the base of device token .so it throughs notification twice if he found the same token twice or more.
Related
Environment:
Ejabberd Version : 16.04
Smack-android-4.1.0
I have created an Android chat application with a XMPP server. However due to Google play permission issue I had to narrow down the feature from app which supported receiving incoming message notifications when the app is in the background.
As an alternative I received the following suggestion from GooglePlay Review Team.
Once you’ve removed this permission, you might consider using Firebase
Cloud Messaging (FCM) if your app’s message delivery requires a
temporary exemption from battery optimization. Please set high
priority only if the message is time-critical and requires the user’s
immediate interaction, and be aware that setting your messages to high
priority contributes to more battery drain compared to normal priority
messages
So at the moment users can send messags via the app. But when he close the app, he will be considered as an offline user, and will not receive any notifications from app. When he opens the app again, he will get all the offline messages those were saved the Ejabberd server.
I want to enhance the current app so that even though a user had closed the app he will still receive a notification when some one sends a message to him (Similar to whatsapp)
Is there a module in ejabberd which integrates the server with FCM and handles this?
If we can not achieve this by Ejabberd, is there a 3rd party library to support this?
If not do we have to write an Erlang module from scratch?
I found similar questions in the internet but I could not find any working solution. Since I am not much experienced with Erlang and would be glad to hear your solutions/ideas on this. Thanks in advance.
This can be achieved in Ejabberd with offline_message_hook. This hook is trigger when sending a message to the receiver and receiver in an offline state. So create a custom module using this hook and you can send a push notification to FCM and APNs servers.
Refer this blog -- https://jasonrowe.com/2011/12/30/ejabberd-offline-messages/
Looks like you need to try apply approach below:
Create REST API for store of user tokens with JID's of users
Create custom hook for fetch XML packages.
Integrate into project the epns library(this library can send FCM/APNS)
In custom hook call the spawn function where will be get the user token from DB by JID and creating payload with sending FCM/APNS notification
I am working on an app and the Android version implements Firebase for Instance ID, Cloud Messaging and Analytics. Everything is working properly in regards to obtaining the instance id and FCM token.
I also built a server API for sending notifications and data payloads to Android devices and in order to use the same methods in the iOS version I decided to use Firebase for iOS for the same purposes (Instance ID, Cloud Messaging and Analytics).
Setting up Firebase on iOS is well documented and I was able to set the environment for everything to work properly. However, when I run the app I got the following error in the console (which means that the instance id and FCM token were not retrieved):
....
[Firebase/InstanceID][I-IID003009] Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
[Firebase/InstanceID][I-IID003007] Failed to retrieve the default GCM token after 5 retries
Wait, I know there are other people complaining about the same issue here but this is a totally different case.
I thought that my setup was incorrect or missing something but I reviewed all the procedures and code and everything was 100% correct.
Where I am located (Damascus, Syria), some services are blocked by Google and can only be accessible via a proxy or a VPN. Therefore I setup a US proxy for both the device I am using for testing and the simulator and when I run the app everything works properly and I was able to get the instance id and the FCM token and log them in the console.
What is weird is that in the Firebase Console the analytics is showing the correct number of users even when the FCM token was not received which means that the communication with the Firebase service is not totally blocked. The only part which is not working (without a proxy) is fetching the FCM token.
My question is: Why this particular Firebase service is blocked in iOS and not in Android and can I do anything about it? Remember that I have no problem in getting the token in Android from the same location. Or is this a bug in Firebase and the service is not location bound?
I have no problem in connecting to Google APIs from my location for other purposes like Google Maps or getting information about an FCM token..etc. However, I noticed that the console is referring to iid.firebase.com instead of iid.googleapis.com.
Any help or suggestion in this regard will be appreciated because I want to make a decision whether I should keep trying to use Firebase in both platforms or if I should rely on Firebase for Android and the native APNs ways for iOS. Also, I want to know if my decision to implement Firebase was the correct one in the first place.
Thanks!
We are integrating two new notifications SDK within the same app. Firebase and Salesforce Marketing Cloud (formerly ExactTarget).
Our IOS versions is working perfectly and no interference has been detected. We send notifications from both tools.
However, we are having problems with our Android versions. The behavior of some of our test-devices is:
Devices are correctly enrolled within the two platforms
Devices receive notifications without an apparent problem
Randomly speaking in terms of time, Salesforce marketing cloud can not notify devices anymore. They are still Opted In within that platform, and ET tries to send the message, but GCM responses with an Error,
InvalidRegistration,2016-11-22
04:00:00,TokenRejection,|ID|8|:(ServiceStatus,ServiceResponse,TrackingDate,FailureType,SystemToken)
Our guess (we’ve done a lot of tests) is that changes in tokens within GCM are producing that problems. We’ve tried to push into Salesforce a new token every time is renew (we get it from Firebase) using their method Registration.getInstance().setSystemTokenInCache(token), with no success up to now.
We did not solve it. We were in touch with Salesforce itself and were given some tips but none of them seemed to work:
Here's what we were told. Rather than creating two projects in Firebase and adjusting the google-services.json file, I just used the sender ID from one project. In your code, you keep the Marketing Cloud initialisation the same and the google-services.json file the same, you only need to change the call
FirebaseInstanceId.getInstance().getToken();
to
FirebaseInstanceId.getInstance().getToken("158036016337", "FCM");
where the first parameter is your sender ID (which is the same sender ID you use in your Marketing Cloud initialisation), and "FCM" is the scope.
What this did was, it returned two different tokens, one from Firebase and one from Marketing Cloud. Both tokens however had an 11 character prefix followed by a colon which was identical. I sent to pushes using both tokens and both worked well. I then subscribed for topics in Firebase
FirebaseMessaging.getInstance().subscribeToTopic("xxxxx");
And sent a push using the Firebase API to that topic and that worked as well. Sent some pushes from Marketing Cloud and that worked as well. I agree that you should test this however.
We solved the issue is a different way. We forced the notifications to be received in our Firebase service (by implementing intent rules in manifest). Then in onMessageReceived() method, we check if the notification from the ExactTarget with PushMessageManager.isMarketingCloudPush(Bundle). If this is true, we let Marketing cloud handle it via
MarketingCloudSdk.requestSdk(new
MarketingCloudSdk.WhenReadyListener() {
#Override
public void ready(MarketingCloudSdk marketingCloudSdk) {
marketingCloudSdk.getPushMessageManager().handlePushMessage(bundle);
}
});
else we handle it as Firebase push notification for our app.
i am not receiving notification after sending it through firebase console , i tried sending many notification but received one or two from around 20 notifications, i followed this guide firebase messaging from github
,why am i not receiving notification, my app is installed in one emulator and in one of my phone but when i receive notification which i have sent through notification panel i get them either on phone or emulator never got them on both.
below is the screenshot of my console
check your android app configuration in firebase console
use a restful client to make the request, i suggest
chrome-extension://aejoelaoggembcahagimdiliamlcdmfm/dhc.html,
there you can see the response of the request, if your request are sent sucessfully or if you have error, and the response tells what kind of error you have
check android app , in the method onMessageReceived and print everything to see if you receive information, besides you can print the property "from" who is the id_number of your proyect, and you can see if the messages come from your firebase android app
check firebase documentation.
I've implemented everything just with the guides and its working pretty well
I solved the same problem.
The problem seems to be the browser compatibility/version. Mozilla Firefox could easily handle this.
Make sure your app is running in the background.
Open the Firebase notification console in the FireFox browser and send notifications.
Make sure token is generated
FirebaseInstanceId.getInstance().getToken();
in my case, the package name defined at firebase console isn't the same as defined on gradle and manifest of the app (i changed it one time in the app), so the app won't be able to receive notifications sent from firebase console.
They both have to be the same!
I did not add a new firebase project, just go to project settings at console and add new android app with another package name and have a look at the newly generated google-services.json and change some lines at you android studio project.
Besides the tips that Pavul Zavala said ، keep this in mind that just data message can received by FirebaseMessagingService even application closed or run in background and notification message can't handle(till this moment) when application run in background.
And all message that sent via FireBase console Contains , they always include a notification key
more detail at :
Push notification works incorrectly when app is on background or not running
In my case, what helped me is creating a new simulator in Android Studio
Few things to check:
in Firebase console https://console.firebase.google.com/ add/configure the project
in Android Studio connect to Firebase - Manu -> Tolls -> Firebase -> Cloud Messaging (Connect, Add FCM to your app)
Send notification from Firebase console
So, again, I recreated Virtual Device (open AVD manger and create the same device with the same API level)
I will be happy if somebody will save the time using this post :)
Ideally it shouldn't behave like that but it might be due to following reasons:
Check the notification priority of your app in the app settings of the device.
You might be sending the token of one particular device, Your target should be User segment.
i am using phonegap-plugin-push to receive notifications.
The very first part, the registration step, works fine on android and ios. I`m saving the registration token on my server and that part is pretty ok.
However, when my server generates an notification, only android version gets notified.
For each device i created a specific api key, as shown in the docs.
But what works for android isn't working for ios.
On android, if my app isn't open i get correctly the notification (vibration+notification)
Is there a way to achieve the same behavior on ios using GCM?
In the end there is no easy solution for that.
As pointed out by #Daniel, the better way to do it is to configure both GCM and APN. a brief discussion can be found here