This article summarizes the Android teaching course from the Geek College Zhang Hao teacher, where Zhang Hao teachers and Tri Yu teachers are very grateful.
(i) Basic knowledge
In the application of Baidu Map development key need to use the content of the digital signature certificate, so here first to introduce.
(1) What is a digital signature certificate (KeyStore)
Digital signatures are used to establish the relationship between software and software authors, and the Android system requires that all applications must be signed by a certificate before they can be installed.
(2) Why to digitally sign an Android app
- The Android security mechanism limits
- Guaranteed Application Uniqueness
- With signature-based permission checks, you can share code and data in a secure way between applications
(3) When the Android app needs to use a digital signature
- All Android apps need to be signed or not installed on the phone
- During the development and commissioning phase, we do not need to sign the app to install it on the phone. The reason is that the IDE has generated a debug signature for me by default
(4) How to view a digital signature certificate
View KeyStore's command: Keytool-list-v-keystore ***.jks
Attention:
- . jks as a certificate file
- As the content of the certificate file, the red box is important content
(5) How to generate a digital signature certificate
- There are two ways to generate a signing certificate, namely the command line and the IDE. Here's an example of how to generate a digital signature certificate with Android studio in the IDE:
1. Build Menu->generate signed APK
2. Click Create New
3. Fill in the relevant information
4. Click OK and then go to the corresponding path to see the newly generated digital signature certificate
(6) How to sign an Android app
1. Follow the steps above and click Next
2. Select build Type, where release represents the official release. Then click on the Finish,android app and the certificate will be signed to generate the full version of the APK.
(ii) Baidu map API Introduction
1. To the Baidu Map Developer Center Application key, here is not described in detail, Baidu Map Developer Center has detailed instructions. It is important to note that the SHA1 value of the digital certificate needs to be filled in when the key is requested. For information on how to view the contents of a digitally signed certificate, view the contents above.
2. Download the jar package of Baidu Map SDK and introduce the Baidu Map SDK, please refer to the knowledge of how to introduce jar package in Android.
3. Configure Mainfest.xml to add the following:
Permissions:
<!--This permission is used for network positioning -
<Uses-Permission Android:Name="Android.permission.ACCESS_COARSE_LOCATION"></Uses-Permission>
<!--This permission is used to access GPS location -
<Uses-Permission Android:Name="Android.permission.ACCESS_FINE_LOCATION"></Uses-Permission>
<!--For accessing WiFi network information, WiFi information will be used for network location -
<Uses-Permission Android:Name="Android.permission.ACCESS_WIFI_STATE"></Uses-Permission>
<!--Get carrier information to support the interface that provides carrier-related information -
<Uses-Permission Android:Name="Android.permission.ACCESS_NETWORK_STATE"></Uses-Permission>
<!--This permission is used to get the WiFi access, WiFi information will be used for network location -
<Uses-Permission Android:Name="Android.permission.CHANGE_WIFI_STATE"></Uses-Permission>
<!--Used to read the current state of the phone -
<Uses-Permission Android:Name="Android.permission.READ_PHONE_STATE"></Uses-Permission>
<!--Write extended storage, write data to the expansion card for writing offline location data -
<Uses-Permission Android:Name="Android.permission.WRITE_EXTERNAL_STORAGE"></Uses-Permission>
<!--Access network, network location requires Internet access -
<Uses-Permission Android:Name= "android.permission . INTERNET " />
<!-- SD card Read permission, user writes offline location data -->
< uses< Span style= "COLOR: #339933" >- permission Android: Name = "android.permission . Mount_unmount_filesystems " ></ uses - permission
Key:
< meta< Span style= "COLOR: #339933" >- data
Android: Name = "Com.baidu.lbsapi.API_KEY"
Android : value= "AK" /> //key: Developer Application key
After completion, it is probably as follows:
4. Finally, we need to emphasize that when debugging Baidu map application, you must configure the Gradule signature file, otherwise it will use the default debug signature file, so Baidu Map API can not be used, because we apply for the key is our own signature file. The configuration process is as follows:
First configure signing in the Project Structure dialog box:
Next Configure Build Types:
The final gradule is probably as follows:
To this, for Baidu Map development of the Android development environment, even if the building is complete.
Baidu Map of Android development--Environment building