Android Widget like WhatsApp to check connectivity and send data - java

I have a running Android app, which sends data to a server. If the device is not connected to the internet, it should be possible to save the data temporarily on the device. If the device retrieves the connection, it should send the saved data to the server. Even if the app is closed.
My question is, how to create a "listener" which listens on the internet connection? This mechanic should work like WhatsApp. In WhatsApp you can receive messages, even when the app is closed.
I've looked a bit around....could this be a Widget? And if it is one, how to not display it on the Home screen? I don't need to display any information there.

You can register for changes to connectivity by following the instructions at Monitor for Changes in Connectivity. When you hear that the phone has connectivity, send your data.
Sorry, I don't know enough about widgets to advise whether they'd be a good fit here.

Related

Receiving message from server instantly while android screen is locked/is in a sleep

I want to write a 'service' app that will be connected to a server, the server will send messages to the app and the phone will popup a notification to the screen instantly upon receiving the message from the server even if the phone is locked. (like Whatsapp/Telegram etc..)
Push Notifications are not instant enough.
I was thinking about using WebSocket for that, but not sure it is the best approach.
What is the best approach?
Sample code will be appriciated!
Thanks.

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 make real time notification in android using retrofit 2

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/

Save chat messages with closed app

Good evening!
I'm developing a chat application that looks like WhatsApp. I need the received messages to be saved on the user's mobile device. Until then everything was ok, because I was saving the messages when the user received the push notification on the mobile, but the problem happens when the application is closed because when the application is closed the push notification does not trigger the received push event (I am using the Onesignal to send the push).
I'd like to know how I can do this, ie get a notification and process it even with my closed application. I think it has to do this because Whatsapp does this and also Spotify also does it when I connect the Spotify to another device it automatically forces the opening of the application on my cell phone.
So my question is, how do I handle an event with the application closed or even force it to open according to a particular event?
I'm using the technology of Ionic 1 and Angular.js. For push notification I am using the OneSignal provider.
Thanks in advance for your attention and hope someone can help me. Thank you!
I'm fairly sure you won't be able to do what you're describing. There is a 'background push' feature introduced in iOS 9 that lets an app receive a payload triggered via push even when it is closed, but that's more for downloading (for example) a new edition of an online magazine, rather than lots of messages.
The difference betwen those two use cases is that if you're subscribed to a magazine, you might want the latest issue to download automatically whilst you have an internet connection, so that you have the issue to read when you're flying/on the train or whatever. A chat app... is pretty useless if you're not connected to the internet anyway, so there's no urgent need to have new messages 'pre-downloaded'
Even if you could do it, I don't think it would be best practice as there's too many scenarios where people won't have internet anyway so you're going to be left without the full message history when a user opens the app (not to mention push notification delivery is not tracked or guaranteed), so you're going to have to do some sort of query when the app launches to download new messages anyway.
If you've got code already that checks and downloads new messages while the app is open, that's great. But if its closed, you'll just need to run some sort of query on launch to download unread messages or something like that

sync data to server android

I'm new to android sync so I really need ideas to get started. Actually my app's requirement is like this: My app needs to connect to my database online. But my android app can be used offline meaning, the user can add records to a local db, say sqlite. And then when the user connects to the Internet, the app should automatically connect to the server and add the record the user added when he is not online. Can you give me some considerations and ideas on how to do this? I really need your help guys. Thanks.
I will recommend you to go for Sync Adapter. See these links
AbstractThreadedSyncAdapter and Creating Sync Adapter.
I have used them long time ago. I will say that it is the best approach for syncing data between device and server. Usually, email apps use these sync adapters.
Sample is also given there. Download it if you want to go deep inside of "HOW".
Thank You!
You need to run background service like android alarm manager. You need to check that device is connected via internet or not. if device is connected via internet then sync the data to server.
Check this like to the way of data sync
How to sync SQLite database on Android phone with MySQL database on server?
Thanks

Categories