Good day. I thought, I thought ... I never did. How can I implement data transfer from server to phone? For example, in VKontakte in a mobile application, when a message comes to the user - only at this moment an alert is received, and instantly.
- the phone calls the server for certain information, the north gives it away. The phone, if available, processes it and then issues a notification. Cause they have callback api + event - Victor
- Hmm ... I knew about the phone-server-phone, but not about callback. Thanks for the answer) - CrazyProgrammist
- vk api callback info - Victor
- Forgrand - sockets / long polling, in the background - pushes (GCM / FCM). - post_zeew
1 answer
This is done by maintaining a permanent connection between the phone and the server through sockets.
Usually they do not do their own implementation, since devaysy, going to sleep, nailing all the processes, eating traffic, battery, etc. Instead, take the google solution - Firebase Cloud Messaging . It works like this - Google services (a program embedded in almost 100% of Android devices) keep a constant connection with Google servers. The system does not nail this connection, because Google is giving its application a special priority that is inaccessible to applications not from Google.
Next, you send a device ID from your server and a message to it to Google’s server, and the device redirects it to the device.
- Thank you so much! Nowhere could this find! - CrazyProgrammist