Push Notifications through Firebase - push-notification

Yesterday Google has announced a new set of tools for Firebase, one of them was Notifications the ability to send notifications from server to devices which are using my app.
But can we now notify users when they receive a new message?
And if not, is there a way around to achieve this?

Looking at the documentation, this doesn't seem currently possible automatically. Here is a possible way to accomplish it "manually" with another server:
Subscribe a user to it's own user ID
In android
FirebaseMessaging.getInstance().subscribeToTopic("InsertUserIDHere");
In IOS
[[FIRMessaging messaging] subscribeToTopic:#"/topics/InsertUserIDHere"];
Setup an outside server that checks every sent messages. When a message is sent, the server should create a notification that includes the recipient's user ID as the topic.
Look here for more info.

You can send messages to group of users (targeting a specific "topic") or to a single device (targeting a Firebase Cloud Messaging token).
To subscribe a device to a topic use:
FirebaseMessaging.getInstance().subscribeToTopic("topicName");
To obtain the device token use (*1) :
FirebaseInstanceId.getInstance().getToken();
Then you can use the Firebase Notificaitons web console, or the FCM server API if you want to send messages from your server.
See: https://firebase.google.com/docs/cloud-messaging/downstream#sending_topic_messages_from_the_server
Notes:
[1] getToken() can return null if the token is not yet available.
You can use the callback onTokenRefresh() to be notified when the token is available and when the token is rotated.
See: https://firebase.google.com/docs/cloud-messaging/android/client#sample-register

Related

Firebase push notification device to device

I am coding a React Native app and I using Firebase push notification service.
In my app, users can send message for each other and I want to notify them when they get message.
I found one way for native android I can code for react native it is not problem just I want to know if there is better way. I can make post to directly to Firebase service with using Http post.
This is the link which way I found: https://blog.usejournal.com/send-device-to-device-push-notifications-without-server-side-code-238611c143
I want to push notification to specific device without server, is there another way to do this?
Sending a message to a device with Firebase Cloud Messaging requires that you specify the FCM server key. As its name implies, this key is supposed to only be used in trusted environments, as knowing it allows one to send any message they want to all users of the app. For this reason it is not possible to secure send messages directly from one device to another device with FCM.
Instead you will have to run code in a trusted environment, such as your development machine, a server you control, or Cloud Functions. Your client-side application code invokes the server-side code, that ensures the call is authorized, and then calls the FCM API.
For more on this see:
How to send one to one message using Firebase Messaging
How to send device to device messages using Firebase Cloud Messaging?

Can my phone receive Firebase push notification if I have installed an app that support it but I have never open it before

Do I need to open the app at least once in order for my phone to receive a push notification?
The must run at least once so it can collect a device ID token and send that to the backend that will send the message. Without that token collected, the app can never receive a message on that device.
Read more about it: What is FCM token in Firebase?
Actually you do not need the device token to send/receive the messages.
However, it is required that the user give permission to receive notifications, and that would only happen during runtime. I tested this and can confirm it works. The device token is only used to subscribe users to specific topics, but you can send a message to all users that have your app installed without needing to specify device tokens.

Can I send push notification without using device token

I want to send automatic push notifications to my clients who are installing my flutter application. Can I do it without getting their device tokens. I am using firestore as my database
You can send messages to client apps using topic messaging, but each client app will need to be subscribed to the named topic. You will not be able to single out a specific device without a device token.

retrieve registered token from firebase console

I understand that client app send request for registration and firebase return with some token which we need to store on our app server so that later can be used for sending notification to particular device. I want to know is there any way to get the same token on firebase server using it's console?
Thanks
The Firebase console has no feature to show what FCM Instance ID tokens have been handed out. If you want to have listing of all the tokens in your app, you will have to store it yourself.

Gamethrive Onesignal Send push from unit to unit

I am considering switching from pushwoosh to gamethrive / onesignal but am a little confused. I am using the Unity SDK and cant see anywhere in the documentation that I am able to sund push from one unit to a specific othe unit. Can anyone help me clarify if this is possible
Thanks in advance
Yes this is possible.
The OneSignal API supports delivering notifications to individual users or groups of users in several ways. In your case, the best way is probably through the device's OneSignal ID (through the include_player_ids field in the OneSignal API).
You can send notifications from one device to another by interacting through the OneSignal API either on your own backend server or from the code running in your app. However, in either case, you will need to have a backend server to store a list of the OneSignal ID for each one of your users.
Here's a rough outline of the process:
Part A (First getting the OneSignal ID):
A device runs your application for the first time
You initialize OneSignal in your application and you receive a new unique OneSignal ID for this new device in a callback
You then must store this OneSignal ID on your own backend server somewhere.
Part B (Delivering a message):
You wish to send a message to a specific user
You ask your backend server for the OneSignal ID of the user who you wish to send a message to.
You use the OneSignal API to send a message to the user.
Related links:
OneSignal Homepage
OneSignal Documentation Home
OneSignal Notification Delivery API Documentation

Resources