Android message push (II)-mqtt-based push function

Source: Internet
Author: User

Some time ago, the company needed the Android-side Mobile Phone Group push function, which we achieved through mqtt.

Mqtt official website http://mqtt.org/

The main architecture of the system is not described in detail. This is related to the issue of professional ethics. Here we will only talk about the mqtt push function.


On the mqtt official website, click http://mqtt.org/softwareto display the source client and server project and library of the agreement.

We implemented it through the apacheactiveclient open-source project.


The following describes how to build a client and a server:

Client:

First go to GitHub (https://github.com/tokudu/AndroidPushNotificationsDemo) website to download mobile client program: androidpushnotificationsdemo.

Shows the running result:


Test_android1 is the unique identifier of the mobile phone, which can be determined by yourself. In many cases, we need to spend more time studying its source code, instead of asking others. We only need to ask when we cannot find a solution, I think this is more conducive to our understanding of the project and continuing to expand.


Server

You can download the server program at http://activemq.apache.org. Please read the documentation of this open-source project carefully.

This project is very powerful and supports configuring the master-slave and distributed servers.


After you build the server, you can use the client to connect to it. Click Start PUSH Service to start the push function.

After the connection is successful, you will see the following interface on the console:



In the server background, you will see:


The red line is your mobile phone device, and then click to enter the following interface:


Finally, click OK to receive the message in the notification bar:



So far, this is the message that the simple server wants to push to the client.



Of course, this is the simplest implementation. Next, you need to expand the server or client according to your company's actual needs.


In fact, the most significant function of mqtt is group pushing. The client can register multiple tokens (the unique identifier of the client) so that all clients can register the token. Then, when sending a message, you only need to send a message for one token, then all the mobile phones have received the message. Like other pushes, you do not need to send each token. Therefore, mqtt Mass Sending is highly efficient. This is good for the mobile phone end. Maybe we need to send all the mobile phones of a program to a certain version of the mobile phone of a program, sending and pushing messages to a mobile phone can be easily implemented using mqtt.


The next step is to study mqtt on your own. Other official documents and some open-source functions have provided a lot of materials for us to learn.

The following is about XMPP protocol push: Android message push (1) -- androidpn (XMPP protocol) demo version officially launched

If the android client program on GitHub cannot run, you can download it for our use (also downloaded on GitHub ):

Http://download.csdn.net/detail/johnny901114/5820151 if you have any questions can leave a message.

Reprinted please indicate the source: http://blog.csdn.net/johnny901114/article/details/8898727

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: 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.