Android push principle
Since the recent project involves Android push, I have read some things about Android push. After summarizing it, we know that the implementation of Android push can be summarized into 3 types:
1. POLL, pull.The general idea is to send requests to the server regularly, and then let the server return information by yourself.
Advantages: Simple implementation.
Disadvantages: Poor real-time performance. If the fixed time interval is small and the number of connections is large, there will be high pressure requirements for the server. It is said that there will be electricity fees... I don't know if it is true.
2. SMS, MMS method. It is said to intercept MMS and analyze the content. This has not been practiced in hand.
Advantages: Simple implementation. Real-time is also good.
Disadvantages: Cost issues of SMS services. expensive!
3. TCP/IP, long-lasting connection.Simply put, it is to establish a persistent TCP/IP connection with the server, and then the server can send you a message.
Advantages: Good real-time performance.
Disadvantages: It is difficult to achieve. It is said that it will also cost more electricity... I have never tested it.
POLL is relatively simple. You can implement basic functions by using Timer and TimerTask timers, as well as several HTTP-related classes, and then parse the server and return information by yourself.
Mainly about the implementation of long-lasting connections:1. IBM-based MQTT implementation. 2. Based on XMPP implementation
There is an Android PN project based on XMPP implementation, which is open source. Although I used MQTT in the subsequent projects. Because Android PN is not mature enough, there are some bugs in it, which I cannot fix for the time being. Because I only looked at the source code on the Android side, maybe some bugs need to be modified according to the server side. (The problem that has troubled me for a long time is that after the server is restarted, the Android PN mobile phone cannot be reconnected. I let it go and chew it when I need it.)
The source code of the project can be found here: /projects/androidpn/ There are 3 resources in the Files tag after entering:
androidpn-server server-side code
Androidpn-demoapp instance (to be honest, it's useless)
Androidpn-client mobile phone code
Added: I remember that after importing the project again, there may be an error message like: unable to resolve target ‘google inc. : Google APIs :7'.
Solution: Right-click the project, Properties, Resource, Text file encoding, other, select UTF-8
Android, Project Build Target, choose Android 1.5
Thank you for reading, I hope it can help you. Thank you for your support for this site!