Sending notification from one app client to another - android

I am developing an Android app, which deals with allocating orders to multiple suppliers. Each supplier will have the same Android app installed. Every day, the in charge of the suppliers will open the app, pick up the suppliers to assign from the recyclerview and enter a customised message on the days' supply in an editText.
The message should be delivered in form of push notification to other suppliers he has selected from the recyclerview. So, in this case I cannot use Firebase console to send notifications. I initially thought of using Twilio to do this. But my client wanted to keep this as last option. They want me to try Push notifications.
I am researching, but every one is illustrating on how the notification can be sent through Firebase console. I also heard that GCM is obsolete now.
Please can anyone give me some pointers on how this can be done? Please note that I am a beginner in Android.

I think you can use firebase cloud messaging to achieve this. See FCM documentation.
You can send a push notification through firebase by using firebase HTTP protocol instead of the firebase console. In this way, you can programmatically send a push notification by making a REST call.
There are 2 firebase HTTP protocols that you may use to achieve this:
Legacy protocol:
This is the older firebase HTTP protocol. This is easier to set up and you can find a lot of material online explaining how to use this like medium article.
New protocol(HTTP V1):
This is the newer HTTP protocol. This is a little more difficult as authentication is done by oAuth token. However, this is more secure and extensible. Also, it seems like firebase might eventually deprecate the legacy API.
Hence, in your app, once the in charge of suppliers assigns the duties, you can call the firebase APIs to send out push notifications to all the assigned suppliers.

Related

How to send the Group Notifications using Firebase Cloud messaging?

I am trying to develop the Messenger App like Whatsapp using Firebase.
I'm already done the code for device to device notifications and now I am trying to send the notifications to specified group.
Please provide the example code for the Group Notifications.
There are a few ways to send messages to groups of users:
Send the message to a topic that all users subscribe to. This is the simplest scenario, since you don't need to keep a list of tokens. But you have less control over the actual people that receive the message, as anyone who knows a topic can subscribe to it.
Keep a list of device tokens for each group in your app server, and then send to each individual device in the group.
You can also use the previous version of the API to send to batches of up to 500 tokens at a time. This sort of multicast delivery is not yet possible in the new API.
For an example of this, see the documentation of Cloud Functions and the sample repo.
Send to a device group with the legacy API. I'd only recommend this approach if the devices are actually owned by one user, which is the case that device groups are meant for.
Try this link
Don't forget this line Authentication:
key=<Your_API_Key>
The word (key) is important

Push Notification from website to mobile app

I want to develop a website that will be able to send push notifications to a mobile application that would be able to run on both android and iOS.
For the last couple of years, I am working as a web developer so developing the website is not something that I am worried about, but I have never developed a mobile application before, the mobile app would only receive notifications from the website so the main functionality would be in the website.
Can anyone suggest me what the best approach is and what I have to learn to be able to do this?
Thank you in Regards
I guess, you have 2 options.
You can either use Firebase FCM
https://firebase.google.com/docs/cloud-messaging/
or use a third party which is called OneSignal
https://onesignal.com/.
If you are looking for an easier way then I recommend using OneSignal instead. You just need to define API Key in your build.gradle and initialize OneSignal in onCreate().
The best approach, in my opinion, would be to use firebase (https://firebase.google.com/products/cloud-messaging/). I think it is better because it is a unique framework for both ios and android and you don't need to worry about the user device when sending the message(you could build an interface in your backend code to handle this but why doing something that already exists and it is free).
The flow is something like this:
on the first start the app(either ios or android) must send its firebase ID to your server so that you can store it (simple http request will od it) and set up a listener for the incoming push messages
when you need to send a push message all you need to do is an http request and you can trigger it with js from your website. The request will contain data such as the firebase id of the receiving device(which you have previously stored)
Firebase Cloud Messaging also have some really nice features like upstream messages(push messages from the device to the server, but you need an xmpp server to listen for them) and topics to send the same notification to many users at the same time
I think the best approach would be to create a node server where the website would be running on and then use Firebase Cloud Messaging (FCM) to send notifications
EDIT: FCM supports both Android and iOS

One to One Android Chat using Firebase

I need some clarifications.
I'm using Firebase realtime database.
Now I've to implement a realtime chat between two android devices. I need also push notifications.
So, the solution based on realtime database is to drop because if the app isn't running, it will not handle the onChildAdded event.
I read on the documentation that I can achieve my aim, using the upstream message from the device to the server.
Now, it's written also that we need an app server.
I just want to be clarified the need of the app server (XMPP or HTTP), and which is the entire flow of message m1 sent from the device A, and the notification on the device B.
In my opinion the app server should act as a man in the middle, so:
A ---> XMPP SERVER ---> FCM
FCM ---> XMPP SERVER ---> B
Is this the flow?
On the documentation I can't understand if I'm right or not.
If so, how do I send a message from the FCM back to the XMPP Server?
The notification message is sent from FCM to the client o from XMPP Server?
Please someone clarify me.
Other solution thought by me:
Since I find really powerful firebase realtime database, I thought these solution to walk around the problem:
Create an app server the is listening for onChildAdded and when it changes send a notification to client device.
Creating a background service on the client app listening to onChildAdded and create notification when necessary.
Even all, I don't like these solutions.
Just want to understand the standard and correct way to achieve my aim.
Firebaser and author of the article debated in the question comments here
To send messages to a device with Firebase Cloud Messaging, you need to specify your project's FCM Server Key. As its name suggests, this key should only be used in code that runs in a trusted environment: i.e. a server that you control.
To send device-to-device messages (such as in a 1:1 chat application where the receiving user is not necessarily online) you need two steps:
one user send an upstream message
the other user receives the downstream message
Using Firebase Cloud Messaging and your custom app server code, you can handle step 2. But that still leaves step 1: the user needs to send a message that somehow triggers your code on the app server. There are quite a few ways to do this.
For example you could implement an HTTP endpoint on your app server and have the chat application send the messages there too (in addition to sending to the database).
You could also implement an XMPP endpoint and have the chat application send the message there (again in addition to sending it to the database).
My article suggest yet another way, one that doesn't require implementing an endpoint at all. It uses a node.js script that runs on your app server and is essentially just a client to the database. Whenever this script detects a relevant chat message, it calls the FCM API and sends the downstream message.
This pattern of using the Firebase Database as your endpoint and then using server-side scripts is quite common when using Firebase. We documented it in our classic blog post Where does Firebase fit in your app? (as option 2) and in this article in the Google Cloud documentation.

Having Some issues with google cloud messaging api for android

I am new to gcm api for android and have for some time now i have being working on an android app to allow chatting between two users of the app. The app is such that a chat can only be initiated when one user opts to contact the other user. But my confusion comes in the manner i would be able to create a chatroom for these two users and for the other user to be able receive messages. since i found out that each user must subscribe to a topic inorder to receive messages in that topic. Would i have to subscribe all users to all possible topics or what? that is my big question but it seems it would have so much overhead considering i have 1000+ users.
Please i need all the help i can get here. Thanks
Would i have to subscribe all users to all possible topics or what?
GCM topic messaging allows your app server to send a message to multiple devices that have opted in to a particular topic.
It is not a requirement but it can ease the work for the server to send messages. In this tutorial, you will see that they have created a chat like environment using GCM without using the topic function.
BUT consider the effects on your server like how will it behave on the potential load when you use the topic messaging, especially the the message will trigger an interaction from the user to the server.

Client triggered Parse.com Push notification

I am creating a simple forum app for ANDROID using Parse. I am stuck at a problem related to notifications
For instance I want that when user A posts a comment in a forum app, user B (who subscribed to that post) will receive a push notification, can I do that using either client code, instead of handling it using Cloud Code, or the REST API? If not then how to I start developing the server side to use cloud code or REST API
Allowing users to send push notifications via the client is bad for security reasons. It's not incredibly difficult to get the application id and client key to an app. Anyone with that information will be able to create their own code that allows them to target whoever they want with push notifications if client push is enabled.

Categories

Resources