Send push notifications when local DB is modified - android

I need to work with android push notifications. I have an app that works with a local database. When this DB is modified i want to send a notification to many concrete person.
I was looking at GCM and Firebase. But i dont know if those ways permit me to do this.
I dont understand good the firebase documentation. If my server side is develope in android and my client side is also in android. I only need to register in FCM service the client side project and then i use the API key that FCM provides me, in the server side with de userID to send notifications?

Related

Sending notification to specific user

I have two version from my app one for the customer and one for the client I need to send push notification to the specific client(in client app) when the customer take an specific action (in customer app).
I know that I should use Firebase Cloud Messaging as it's a new replacement to GCM, but I can't figure out how I can do this in both server side and client side.
you have a lot of options here!
let's start with the server side:
you have two options HTTP or XMPP, HTTP is a one way connection XMPP is two way.
for your app you will need XMPP for upstream and down stream messages
check there Guides it's really great: Server guide
there is also a Java and Node.JS Admin SDKs but i don't know much about.
but there is a great Tutorial which describes the whole proccess if you go for Node.js
So what happens is:
when a device sends an upstream message
Firebase will forward it to your server
Your server should handle the message and send it to the other device through Firebase cloud messaging
you can implement a server-less app using real time databse but you will not receive message in background, but when the receiver app is running it listen to databse changes and send notification to user
you can also make a server listens to databse changes "instead of receiver" and take actions upon it"send a message to the other device"
Edit:
with the new cloud function feature you can now use it to send notifications to users based on database events,
so you can add your message to database in a class
and make a cloud function to listen to this class write events
and whenever a message saved to this class, it sends it to desired
receiver
so now you don't need an external server to send notifications to
devices
check this cloud function sample, it's an example of sending notifications based on database event.

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.

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.

Is PHP necessary to implement GCM

I am trying to implement android push notification by using GCM. But, in all the tutorials that I have referred so far, I get one or more PHP files. Is it not possible without PHP, because I don't know PHP. Any help will be appreciated.
I f you want to implement GCM you'll need a mediator file php/.net etc which acts as communicator between your server and the GCM server.This file pass the message to be delivered along with the projectid(registered with google console)to GCM server.So that GCM server can send push messages to all mobile devices regisytered under the corrosponding projectid.You can use this based on your purpose.
You don't have to have PHP for GCM, you can use any server side language i.e. Java (J2EE), Python, etc. But what you must have is a server.
See what android is saying about GCM here
A full GCM implementation requires both a client implementation and a
server implementation. For more information about implementing the
server side, see Implementing GCM Server.
Some similar questions:
GCM java server example
How to send notification to Android app from Java server using GCM?

GCM server direct from android app

I am creating a chat application on android using GCM. I'm already able do receive messages from the cloud and to send them manually through a PHP script using cURL. I can simple make an HTTPRequest to this script everytime a user send a message but I would like to know if there's a way to remove this script thus making the android app directly send the message to the cloud. If this is possible I also would like to know if it is the "right" way to do it or if the HTTPRequest is as good as it.
Thanks in advance.
Not really. GCM is not meant to replace your entire infrastructure, just the push channel from your servers to the clients.
That said, there is this concept of Upstream Messaging (from device to Google's servers) but Google's servers then contact your servers (via XMPP of all things) to let you decide what to do next.
You cannot do device-to-device over GCM.

Categories

Resources