Full analysis of the perfect solution for Android message push

Source: Internet
Author: User
Tags android push notification android games

Push function is becoming more and more important in mobile phone application development, and has become a must for mobile phone development. In Android app development, because of the well-known reasons, Android message push we have to make a lot of trouble. This article is used to discuss a perfect solution for Android message push.

First, the message pushes the foundation

Message push is a new technology that reduces information overload on the Internet by periodically transmitting information that users need. Push technology reduces the time it takes to search on the Web by automatically transmitting information to the user. It searches for and filters information based on the interests of the user, and periodically pushes it to the user to help them efficiently discover valuable information.

When we develop mobile applications that need to interact with servers, we basically need to interact with the server, including uploading data to the server and fetching data from the server.

In general, the client and server communication client is active, but there is a problem is that once the server data is updated or the server to send a notification to the client can only wait until the client connection can be achieved. This way the message loses its real-time nature.

How to enable the client to receive the server's messages and notifications in real time, in general there are two ways, the first is that the client uses pull (pulls) the way, is to go to the server at a certain time to obtain information, see if there is updated information appears. The second is the way the server uses push (push), when new information is available on the server side, push the latest information to the client. This allows the client to automatically receive the message.

While pull and push two ways to get server-side update information, it is obvious that push is more advantageous than pulling mode. Because the pull mode is more cost to the client's network traffic, and the main is the charge, but also need our program constantly to monitor the changes in the server.

Second, several common solutions to achieve the principle

1) Polling method: The client periodically sends an inquiry message to the server and synchronizes the message as soon as the server changes.

2) SMS (Push) mode: To understand the server's commands by intercepting SMS messages and parsing the contents of the message, but this way the average user is financially hard to bear.

3) Persistent connection (Push): A long-term connection is established between the client and the server, which enables the timely and real-time delivery of messages.

III. Overview of Message push solutions

A, C2DM cloud Push solution

Google offers the C2DM (cloudto Device Messaging) service on Android mobile platforms. Android Cloud to Device Messaging (C2DM) is a service that helps developers send data from a server to an Android application. The service provides a simple, lightweight mechanism that allows the server to notify the mobile application to communicate directly with the server to obtain application updates and user data from the server.

The main problem with this solution is that C2DM needs to rely on Google's C2DM server, which is often unavailable due to the domestic network environment.

B. MQTT protocol for Android push

The use of the MQTT protocol for Android Push is also a solution. MQTT is a lightweight message publishing/subscription protocol that is the ideal solution for implementing a messaging push server based on a mobile client.

Wmqtt.jar is an implementation of the MQTT protocol provided by IBM. We can download the instance code of the project from here (Https://github.com/tokudu/AndroidPushNotificationsDemo) and find a server-side implementation that is written in PHP (https:// github.com/tokudu/phpmqttclient).

C, RSMB implement push function

Really Small Message Broker (RSMB), is a simple MQTT proxy, also provided by IBM, with the view address: HTTP://WWW.ALPHAWORKS.IBM.COM/TECH/RSMB. Open port 1883 by default, which is responsible for receiving messages from the server and forwarding them to the specified mobile device. Sam is a PHP library written for Mqtt. We can download it from this http://pecl.php.net/package/sam/download/0.2.0 address.

D, XMPP protocol for Android push

Google's official C2DM server is also packaged using the XMPP protocol. XMPP (Extensible Communication and Presentation Protocol) is an Extensible Markup Language (XML)-based protocol that is used for instant messaging (IM) and online probing. The agreement may eventually allow Internet users to send instant messages to anyone else on the Internet.

ANDROIDPN is a Java open source Android push notification implementation based on the XMPP protocol. It contains the full client and server side. But there are some shortcomings:

1) For example, when the time is too long, it will never receive the push message.

2) The performance is not stable enough.

3) If the message is pushed out of the server, it is no longer managed, regardless of whether the message successfully arrives on the client phone.

If we want to use ANDROIDPN, then we need to do a lot of work, need to understand the XMPP protocol, understand the implementation mechanism of ANDROIDPN, need to debug internal bugs.

E. Use of third-party platforms

At present, there are some push platforms available at home and abroad, but it involves charging, secrecy, service quality, expansion and so on, and we have to be deterred.

Four, the message push the perfect solution

Combined with the above discussion, there are plenty of options for building Android messaging, but each has its pros and cons. However, it is best to build a push platform on your own. Because you have, he is inferior to own.

For example, it is recommended to use a "certain Android message push component" on the build-own push platform. The group can be used not only to use, but also to provide the source code to expand, to achieve their own special needs.

A, Push principle

The Android Messaging push component implements Android push based on the XMPP protocol. XMPP (Extensible Communication and Presentation Protocol) is an Extensible Markup Language (XML)-based protocol that is used for instant messaging (IM) and online probing. The agreement may eventually allow Internet users to send instant messages to anyone else on the Internet.

The implementation principle of the Android message push component is as follows:

Figure 1-Message push schematic diagram

The Android Messaging push component consists of a server part and a client part. Each part is comprised of an XMPP protocol component and an external interface component. The XMPP protocol component is responsible for connection management, message communication between the server and the Android client, and the external interface component is responsible for receiving commands from the application system, the client application, and sending the received notification message to the application system.

The Android Messaging component provides Tomcat-based server applications and Android development jar packages. Where Tomcat-based server applications are deployed directly on Tomcat, Android development jar packs can be introduced into Android projects.

B Integrated Mode

1) Server Deployment

The Android Messaging component Tomcat Server app is deployed directly in Tomcat with the port number set arbitrarily.

2) client Jar Package Reference

Build the Libs directory in your Android project, and then copy the supplied Android development jar package to that directory. See:

Figure 2-jar Package Introduction diagram

3) Android Project Androidmanifest.xml file modification

Add the following permissions to the file:

    1. <uses-permission android:name="Android.permission.READ_PHONE_STATE"/>
    2. <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"/>
    3. <uses-permission android:name="Android.permission.INTERNET"/>
    4. <uses-permission android:name="Android.permission.ACCESS_WIFI_STATE"/>
    5. <uses-permission android:name="Android.permission.CHANGE_WIFI_STATE"/>
    6. <uses-permission android:name="Android.permission.VIBRATE"/>

To register a service in this file:

    1. <service android:enabled="true"
    2. Android:name="Com.bjjrs.server.NotificationService"
    3. android:label="Notificationservice" >
    4. <intent-filter>
    5. <action android:name="Com.bjjrs.server.NotificationService"/>
    6. </intent-filter>
    7. </service>

At this point, the Android Messaging component integration work is complete.

C, interface mode

1) The server-side interface uses HTTP protocol-based access, using the HTTP protocol to obtain a variety of information from the server, to achieve the push of notification messages.

Queries for various user messages can be implemented using the following methods and parameters:

http://localhost:8080/user.do?action=getalluser&isonline=&userid=&usertype=&deptid=& Deptname=&realname=

You can push a variety of messages using the following methods:

Http://localhost:8080/notification.do?action=pushNoti&userNames=&title=&content=

2) The Android Client interface uses a broadcast mechanism.

Message ingestion: When the XMPP protocol component receives a push message, it broadcasts the message in a certain format, notifying the client that another app is receiving and processing the message.

Message sending: When a client application needs to send an instant message to a server or other client, it simply broadcasts the message in a certain format, and the XMPP component automatically receives the message and sends it to the specified other client.

D, advantages and characteristics

1) system integration is simple and requires no complicated setup.

2) The Android client application and the Android message push component are completely separated, and the interface is called by each other to realize the optimization of the module application.

3) The client communication mechanism adopts broadcast mode, which brings great flexibility and expansibility to the client application, and can handle the received push message freely.

4) The Android message push component has the functions of message store, message resend, message routing and so on on the server side, such functions as disconnection, confirmation, reading confirmation, message sending, command execution etc. in the client part, ensuring that the message can be pushed to the client, and also ensure that the client can receive and read the message.

E. Scope of application

The Android Messaging push component can be used in the following scenarios:

1) for message push. such as: Notice release, emergency command.

2) User timely message interaction. such as online chat, work interaction and so on.

3) for remote control. such as controlling the status of remote clients, data escalation and so on.

Finally, I hope that the reproduced friends can respect the author's labor results, plus the reprint address.

Http://bbs.hiapk.com/thread-4652657-1-1.html

"Editor's recommendation"

    1. The Android hide feature that you should be most concerned about
    2. How Android and iOS defend against malicious apps
    3. Conjecture about the Android wearable SDK
    4. Best Learning Roadmap for Android games and app development
    5. Top ten navigation design errors in Android apps

Full analysis of the perfect solution for Android message push

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: info-contact@alibabacloud.com 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.