how to make real time notification in android using retrofit 2 - java

I want to make real-time notification in my android app, but I don't know how to make it real-time and connected to the database
how to make my app can get/access data change from the database every time the database changing even when we didn't open the app
let's say every time admin sending notification, it will send data to database and it has column "read" and it will set to 0 and then user's app will immediately receive notification where the column "read" is 0, and when user opens the notification it will open an activity and change column "read" from database to 1.

You can use either firebase cloud messaging or user background notification service with web socket connection

There are many ways to achieve this type of real-time communication like,
Socket.
MQTT Protocol.
WebRTC.
Firebase Live Database.
Also, you can achieve this feature by sending notification from your admin panel to the user's mobile devices.

A common way is to implement Firebase(FCM) in your application and on your server. You can see how to implement FCM using this Offical documentation help Link https://firebase.google.com/docs/cloud-messaging/

Related

Notification in Android Studio y Firebase Database when the app is closed [duplicate]

I am creating an Ionic 2 app with firebase and I need a way to listen to database changes (specifically on child_added) when the app is closed (I.e. in foreground,background and killed)
Basically, I want to use WebRTC to make calls within the app like whatsapp and I am following this post - https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo
However, the only thing that puzzles me is how it will work when the app is closed. Can anyone please help me understand?
Thanks!
It's not possible to actively listen to database changes using the Firebase client SDK in exactly the same way that you can when your app's code is running.
If you want your app to receive information about changes to your database, you can instead use Firebase Cloud Messaging to send your app a notification with a small payload that contains information about the change. When your app receives the notification, it can then make a decision about what to do. There are some limitations with web support, so be sure to read about that.
Also look into Cloud Functions for Firebase to make it easier to write some server side code that can trigger in response to a database change and send a notification when those changes happen.

How to send notifications depending on the Firebase data using Firebase Cloud Messaging

I have an app where people sign up for events and I want the app to notify the users registered for and event the day before it happens. All the data is stored in Firebase. So basically I would like to know how do I make my app read from Firebase the data from all the users in a regular basis and if a user is signed up for an event and the date is close send him a notification, without the admin having to do anything or using the console. Thanks
If you want to make this process automatic You can write Firebase cloud functions and can add triggers on nodes to execute cloud function, In that cloud function you can send push notifications using FCM depending upon your requirements. here are the helping links
Firebase Cloud Functions
Firebase Cloud Messaging
Otherwise if want to avoid cloud functions you can directly send message from App to App using FCM without involving server.
If you're looking to keep all of your server side logic running off of Firebase, the Firebase Cloud Functions are what you're looking for.
Here is the documentation for setting up functions to be run on a schedule: https://firebase.google.com/docs/functions/schedule-functions
If you're not looking to run your service from the Google Cloud, then the next best option is to setup CRON jobs if you're using a Unix based system, or the Task Scheduler if you're running a Windows based system.

Firebase: Send push notification to user on all their devices

I am building an app similar to Instagram. User uploads a post and other others can like it. When people like the post, I want the post author to get a push notification using FCM (Firebase Cloud Messaging).
My problem is that the refreshToken (that is generated using FirebaseInstanceId.getInstance().getToken();) is specific to the device. So if the same user logs into the app from a different device, I want to make sure I send a push notification to all the devices. So here is my proposed solution, I want to know if it's the right way to do it:
Every time user logs into a device, I store the refreshToken into the database and when I want to generate a push notification, I can iterate over all those refreshTokens and send a push notification to all those devices.
Is there a better way to accomplish this?
Note: I am aware of Device Group Messaging and I can't use that because I don't have an app server. And I don't want to do it on the client side because that requires the client to have a Google account.
Yes, the implementation is okay.
Every time user logs into a device, I store the refreshToken into the
database.
This is actually not necessary to send the device push registration id (refreshToken in your case) each time user logs into your application from a device. You need to send the push registration id (i.e. refreshToken) from your device only when the device is not known to the server yet (i.e. new device).
Is there a better way to accomplish this?
I think no. This is the perfect way that you have implemented. However, we might always think of several optimization points like, tracking which devices are logged off, so that you do not need to send the push notification to that device any more. So in case of logging off from a device, send another invalidate refreshToken request to the server from that device, so that it does not get any further push notification. This is an improvement over the current implementation.

Push notification in local web without internet

I'm aware of GCM services for push notifications, but I have this issue.
I have a android app which will send a data to a local web server (php) that will response to another android device with the data sent, a normal push notification with GCM, I think.
But I need this to work even without internet, because it is a local web app that will work only that.
Is that even possible? Android device X send json data to web server that will send the data to other android device Y.
How can I verify that exists new data in the device Y ?
Thanks. I know its a little wierd.
Yes, it is possible. But it is not easy to develop. This is why:
Push notifications work attached to an account service. So you would have to implement an Authenticator service and then the whole push platform yourself.
I would not use GCM for what you are doing though. If it is working on a local network, you can use "polling" (request the server every now and then for updates)

Android WebView with notification on new message

I have messaging php based application where users login and send messages to each other.
I created an android app that is a WebView pointing to that website to give and in-app feeling to my users.
Now I'd like to add a notification feature to the app which will notify users every time they receive a message.
Is it possible to do so with a WebView based application ?
Thanks
You could send a notification from the php using Google Cloud Messaging every time there is a new message for that user.
Take a look here http://developer.android.com/guide/google/gcm/index.html

Categories