The Firebase Console allows us to send notifications to single users, groups, users subscribed to topics or to the entire user base. Is there any code that allows us to directly send notifications in the same way, but programmatically?
For example, if I had a list of users (containing their Firebase UIDs), if I click on one of the users, could I send a notification to that user through Firebase the same way the console allows us to send a notification through the console?
This Firebase Blog uses the Google App Engine Flexible Environment to actually send the notifications, but it requires a free trial and costs money.
This Quickstart doesn't really show how to send user to user notifications. It focuses on the subscription-based notifications, but this isn't really what I need.
Is there any good way of doing this with Java/Kotlin and the Firebase API?
FCM doesn't support you sending message directly from Android app to Android app. However, this is a workaround to solve your problem:
Create a firebase cloud function. Listen a special path in firebase database
Android app 1 push a data (maybe Android app 2 ID) to this path
Firebase cloud function process data, determine who to send notification (Android app 2).
Firebase cloud function push notification to Android app 2.
ref: https://firebase.google.com/docs/functions/use-cases#notify_users_when_something_interesting_happens
In a basic concept: we write our server to get action from firebase database and decision to send notification to other user by FCM. This our server can write with NodeJS or using Firebase Cloud Function (above)
Guide how to using Nodejs is here: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
Related
I want to add push notification to my app with Firebase Cloud Messaging but i don't know the right way to set this up.
My app looks like this:
I have multiple customers (companies) who host their own server with a database for their employees.
Every employee of my customers will download the app to receive push notifications from their company's server which implements the firebase admin sdk to send push notifications.
I thought the easiest way would be to let every customer set up their own fcm project and then add the api key to the app.
This is easy to set up in android, but in ios every company would need an apple dev account for the certificates which costs them 99€ every year just too receive push notifications.
So maybe only i need to set up one firebase project myself and generate a server key for every customer. This way only i need a apple dev account.
Is it possible to let every customer send push notifications through my fcm project to their employees but not to any other employees of different customers. They should not be allowed to see any data of other customers or send messages to them.
What's the intended way to set this up and is there a limit to push notifications in one firebase account? If only i host a fcm project for every customer i might hit the limit.
Thanks in advance for your help.
They should not be allowed to see any data of other customers or send messages to them.
If you require isolation between customers, then they should definitely not be using the same project. They should be in different projects, so they can't send messages outside of their own user base.
I'm developing an application for my College:
Users (students) login on it with their college credentials, once they are authenticated, the app creates a Firebase Database data for that user containing al his info, including the disciplines(subjects) that he is on course.
Then comes the Firebase Cloud Messaging part, the users can send notifications for other users that are on the same disciplines.
Example: I'm coursing Math, then can I send a notification to the others users that are also doing Math. There are hundreds of disciplines in my College.
My idea is to send the notification to all of my app's users then, before notifying, handle with some code to check if the user is registered to the notification's target discipline or not, if he is, send notification, else, do not send anything, in others words, filter the message before showing the notification!
I studied several Firebase Cloud Messaging docs and examples but I couldn't find a way how to do it... Can somebody give a light?
Yes, actually, it'd be best to decide server-side on the group of users that will receive the notification, meaning, you need to have them in some sort of group. Firebase has a concept of group and subscription for messaging. And you can setup a cloud function to actually send the message to the clients
https://firebase.google.com/docs/cloud-messaging/js/send-multiple
I am developping a mobile application that must implement push notifications. Documents are stored on a SQL database, and people should be able to edit these docs after downloading them offline, then the modifications should be saved in the SQL Database once the phone is online again. People should be able to receive notifications when the app is closed.
I heard that I need push notifications, and for android there is Firebase Cloud Messaging (FCM). But is it possible to use FCM with my SQL database ?
All tutorials in the docs only speak about connecting the app with Firebase
For your project you need a server with your API, SQL Database... and a push notification server that ask FCM services to notify your registered devices.
FCM works like that :
You add the FCM plugin in your Android/iOS app, then when you launch the application it will ask FCM for a unique token associated for your device and this app. You will store that unique token in your push notification server, I advise you to associate it with a user identifier or one thing that you will use to identify the device to notify.
When your first server (with the APIs and the Database) did some action and you want to notify a device :
The server will ask your push notification server to notify a list of devices that you will probably determine with the user identifier like I said earlier, then the push notification server will find the associated tokens and send all of the pre stored tokens to FCM with the notification content you want to send, you can also send parameters that will be used to do special actions in your mobile app.
Finally FCM will notify your devices :)
Hope it helps.
Is possible to send push notifications with firebase without using the console,I mean can I send a push notifications when some user makes some action in the app?
Is possible to send push notifications with firebase without using the
console
Yes you can use Firebase API
I mean can I send a push notifications when some user makes some
action in the app?
You can subscribe to a topic when user makes some action in the app
FirebaseMessaging.getInstance().subscribeToTopic("news");
and send a notification from Firebase web console or use Firebase API to all topic subscribers.
You can send a message to a topic from the Firebase Cloud Messaging API.
But this requires the use of your FCM server key, which means it should only be done from an app server. You should never embed your server key in the client-side app. This means that direct device-to-device notifications are not possible at the moment, you will always need an app server for that.
For a tutorial explaining one possible scenario, see: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
I want to send push notification in my app (Android) using Google Cloud Messaging. I am using firebase for backend. As firebase do not support inbuilt push notification i am using Google App Engine.
I do not have any idea on Google App Engine. Right now i am using a template provided by google for sending push notification.
Google Cloud Messaging Template Github
Till now i have deployed my app in Google App Engine and i am able to send push notification to all devices that are registered (From Web) An HTML page i get when i use GCM template.
What i want to do is , to Listen for Firebase data change and send push notification to user who is not online or has closed the app.
How can i run a servlet in background so that it keeps running in background and send push to user who is not online/connected.
As i have only push notification logic in Google App Engine Should i use servlet or struts.
Thanks in Advance
It is my understanding that Firebase really doesn't work very well with GAE, so you might want to reconsider your choices.
Listening for data changes, as you have mentioned, requires that your app leave a background thread running. To do this on GAE you have to disable automatic scaling which is an important feature of GAE.
You could create a separate backend GAE module with manual scaling and then have it use eg. a queue to notify your main GAE module of a data change, but this seems to me to be unnecessarily complicated and inefficient.
Hopefully Firebase will improve their product so it can notify of data changes in a more efficient and flexible manner, but in the mean-time, perhaps you should use a regular compute engine instance.