Location-aware-instant: Android client for real-time location awareness development

Source: Internet
Author: User

I. Review

Before sharing this project, let's review the previous three articles.Article:

Location Awareness Service Based on instant messaging and LBS technology (I): Proposing Problems and Solutions (Internet address)

In the first article, we raised the need to allow a and B to immediately obtain the exact location of each other in different places. Then we discussed the solution to solve this problem. That is, we abandoned the round robin (pooling) method to update data on different clients, the reason is that B does not know when a needs its own location information, so B can only post its location data to the server all the time, and a needs to regularly get B's information from the server through restful Web requests.

Finally, it is determined that the XMPP-based pubsub (publish/subscribe, publish/subscribe) method is used to transmit asynchronous messages in real time.

Location Awareness Service Based on instant messaging and LBS technology (II): XMPP protocol summary and open-source solutions (Internet address)

The second article mainly summarizes the XMPP protocol and why XMPP is used. Finally, it introduces the XMPP Java open-source solution: openfire + smack + spark.

Location Awareness Service Based on instant messaging and LBS technology (III): Building an openfire SERVER + testing two IM clients (Internet address)

The third article explains in detail the XMPP-based openfire service setup and the use of two heterogeneous XMPP-based desktop clients to test instant messaging.

Note: In order to better understand the problems to be solved in this project, we strongly recommend you read the previous three articles.

Ii. location-aware-instant Project Overview

Location-aware-instant is an android application running on Android OS with the location-aware function.ProgramClient. Like the two desktop programs introduced in the third article, the open standard XMPP protocol is followed.

During the development process, I found and referenced a lot of foreign materials and related projects, and used the weekend and evening time, and now I have finished 90%.

The architecture and technical basis of this program:

1. Android OS Application Development Technology: including map application development.

2. openfire server: open-source Java server program based on XMPP protocol.

3. Smack Development Library: a Java development kit that encapsulates the XMPP protocol on the client. This project uses asmack Library (suitable for smack optimized version with Android OS ).

The implementation principle of this project. There are three levels:

1. First, use openfire as the server and use the asmack database to develop an instant messaging program with a contact list;

2. The client then embeds its own interception pre-processing logic between sending and receiving messages, and customizes special commands to implement automatic message response;

3. when receiving a message, the last layer determines whether the other party's intention is to locate the request based on the pre-processing command. If so, it calls the location locating method to obtain the local location and automatically restores the request to the sending Party, the requester determines whether the received message is related to the location based on the pre-processing command. If so, the requester locates the location of the message on Google map.


Note: This article describes an application, notCode(This project may be explained in conjunction with the android Development Summary later ).

Iii. Project function display

Because there is only one test mobile phone HTC G6, and this project is location-related, Android development simulator is used to reach the most communication end.

The test account is a test2@ (because you are logged on to the location-aware-Instant Client on HTC G6), a test@ (used to log on to the location-aware-Instant Client on the simulator ). The above two account format is jabber ID (XMPP protocol account, you can refer to the front of the second article about XMPP), was originally to use test@im.comit.com.cn in other Desktop client resolution normal, however, the mobile phone resolves the domain name of im.comit.com.cn into another IP address, so I directly use the IP address of my local machine.

The logo of this program:, the logo comes from Baidu encyclopedia's XMPP Introduction:, I simply handled it.


1. First, the login interface (use the two accounts above to log on to the two mobile clients ):

Login interface of HTC G6 development simulator login interface


2. When both Parties log on to and connect to the openfire server, the online status of both parties may occur. That is, you have registered your status on the server to be online.

HTC g6 can see the opposite party (TEST) Development simulator display Test2 online


3. Operation (currently, only the target user can be located. In fact, you can also send common information, delete contacts, and add Contacts)



4. First, let's take a look at the demonstration of positioning the HTC G6 client through the mobile phone simulator, that is, click the "get location" option operation of the mobile phone simulator (on the right) in step 3.

Although the test environment is indoors, GPS signals cannot be obtained. However, HTC G6 is inserted with China Unicom's 3G card, so you can use the base station to locate the approximate location in real time indoors.

In this case, the mobile phone simulator sends a location-aware request to G6. G6 should respond to its location. In less than two seconds, the result is as follows:


I live in a region, so G6 probably located my location through the base station and responded the location data to the mobile phone simulator. The simulator located G6 on the map.


5. The above demonstrates how to locate G6 through the simulator, and now shows how G6 gets the simulator location. However, because the mobile phone simulator cannot obtain the real location information, it cannot reply its own information to G6. The solution is to enter a custom location data in the development tool. For example, enter the longitude and latitude of the company (23.143791, 113.347533 ).

In the figure, emulator 5554 is our simulator (ht03gnx0404 is the HTC G6 mobile phone ). In this way, the simulator is positioned in the company.


Now try to use G6 to perceive the location of the simulator client, that is, click the "get location" option in HTC G6 (left side) in step 3. The result is as follows:

The G6 client is waiting for a response from the phone simulator. In less than two seconds:


OK. The location of the mobile phone simulator is located, that is, G6.


Here, the basic framework of the mobile phone Location Awareness Service has come out. It can detect the location of the other party. Is it cool!


4. project content and structure introduction (the code is too long and divided into the upper and lower parts)

Figure 1 Figure 2

Code structure introduction: the following package names ignore the cn.com. COMIT. locationaware parent package

Figure 1: chat package: Class Related to message sending

Data Package: contact list, message, and other entity classes

Dialogs package: Dialog Box class related to interaction

Exception package: exception-related classes

Map package: Class Related to map and lbs

Figure 2: service package: encapsulate the smack Library and the XMPP service provided by the other party.

Util package: tool package

Widget. quickantion package: Contact operation (for example, "Get location" in step 3) Operation Option control class

Cn.com. COMIT. locationaware parent package: Entry and auxiliary class

Google APIs 2.2: Google Android map Development Kit referenced

Reference Library: asmack-2010.05.07.jar-smack Android optimized version of the api library, Trace. Jar Error Tracking related package.


V. Conclusion

1. In traditional network operations, we use restful get to obtain data and post to submit data, but this is not omnipotent (although it can solve most network application problems ). The introduction of Instant Messaging Based on pubsub (publish/subscribe) can sometimes achieve unexpected experience. This project proposes a research direction and ideas (although there is still a long way to go before commercialization, after all, you can find one and take the "first step of the long journey ").

2. Recently, LBS-based applications have emerged one after another, enabling the integration of LBS and instant messaging to make the research direction clearer (for example, the automatic response function of this project ).

3. The combination of instant messaging and LBS may be referred to as the legendary "micro-innovation". After all, innovation does not have to be created.

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.