Android message push

Source: Internet
Author: User
Tags android push notification


Message pushing means sending a connection from the server to the mobile terminal and transmitting certain information. For example, some news clients receive one or more notifications at intervals, which is the push messages sent from the server, and some common IM software such as Gtalk, all have the server push function.

The push method is as follows:

1) Communicate with the client through SMS.

On the Android platform, you can intercept SMS messages and parse the message content to understand the intention of the server and perform complete real-time operations. However, the problem is that the cost of this solution is relatively high and dependent on operators.

2) Cyclic active timing acquisition

This method requires the client to make a scheduled or periodic access to the server interface to obtain the latest message. Too slow polling frequency may lead to delay of some messages. Too fast will consume a lot of network bandwidth and battery.

3) persistent connection

This solution can solve the performance problem caused by polling, but it will still consume the cell phone's battery. We need to establish a service to maintain persistent connection with the server (Apple and Google's c2dm are like this ). However, for Android systems, when the system has low available resources, the system will forcibly disable our services or applications. In this case, the connection will be forcibly interrupted. (Apple's push service works very well because each mobile phone only maintains a connection with the server. In fact, c2dm works like this. That is, all the push services are completed through a proxy server. In this case, you only need to maintain a persistent connection with a server. C2dm =Cloud to device messaging).

In contrast, the third method is the most feasible.Write System services or boot functions for the software; orIf the system resources are low, you can restart the service in the ondestroy () method after the service is shut down to achieve persistent connection.

C2dm is built into the Android 2.2 System and cannot be compatible with the old 1.6 to 2.1 systems. It depends on the c2dm server officially provided by Google. Due to the domestic network environment, this service is often unavailable.

The XMPP protocol established on TCP not only provides the persistent connection function, but also enables duplex communication between servers and clients, and does not depend on the system version or Google server, provides a better solution.

2. XMPPProtocol

XMPP stands for extensible messaging and presence protocol, formerly the jabber project. It is an XML-based open instant messaging protocol. XMPP is exposed by many Internet users due to Google Talk and Netease bubble applications. A key feature of XMPP is its Distributed Instant Messaging System and XML streaming.XMPP is currentlyIETFThe International Standards Organization has completed standardization.

Android push notification(Androidpn) is an open-source Java implementation based on XMPP protocol. It contains the complete client and server. This server is basically modified and implemented on the basis of another open source project openfire.

The androidpn client needs to use a Java-based open-source XMPP protocol package asmack. This package is also based on the openfire's other open-source project smack, but we do not need to compile it ourselves, you can directly mount the asmack in the androidpn client. jar. The client uses the xmppconnection class provided in asmack to establish a persistent connection with the server and use this connection for user registration and logon authentication. This connection also receives notifications sent by the server.

the androidpn server is also implemented in Java. It is based on the openfire open source project. However, its Web part adopts the Spring framework, which is different from openfire. The androidpn server consists of two parts. One is the XMPP service listening on port 5222, which is responsible for communicating with the xmppconnection class of the client. It serves as a user registration and identity authentication, and sends push notification messages. In addition, a web server uses a lightweight HTTP server to receive users' Web requests. The two methods of the server are of extraordinary significance: when the corresponding TCP port is closed by the firewall, you can use the round-robin Method for access, and thus help through the firewall.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.