Objective
Location service is one of the most commonly used functions on mobile devices, based on the Android source code, the architecture and implementation of the positioning service in Android system are analyzed in detail. The positioning service is a system service provided by the Android system, where all system services are similar in architecture. It's easy to understand just one and then understand the other. For Android application developers, this article can help them understand the implementation behind the APIs they use. For Android system developers, this article can help them better understand the Android architecture. For information on how to obtain the Android source, see the official website of Android Source: The http://source.android.com/source/downloading.html Android source contains a lot of files, some The source file is even the same name. In order to clearly indicate the file we are discussing, this article will indicate its path in the Android source tree when referring to the source file.
Android.location Package and API code example
The API that the location service provides to the application tier is located in the Android.location package, which contains classes and interfaces as shown in table 1:
In table 1, the most important class is Locationmanager, which is the entry class for the entire positioning service. Listing 1 is a code example that uses the positioning service API: