Android requires that each application be digitally signed before it can be used. The signature contains information such as the key, creator, and Creation Unit, and is saved in a keystore. Google map provides the map service for every registered application. application developers need to transmit the keystore fingerprint to Google to obtain the API key. When applying for the map service each time, transmit the API key as a parameter to Google. Google can determine the application's needs based on the API key from the client's legend and determine whether the application has been registered.
Google map in Android is implemented using the mapview control. Its definition in the XML file is as follows:
[Plain]View
Plaincopy
[HTML]View
Plaincopy
- <Com. Google. Android. Maps. mapview
- Android: Id = "@ + ID/mapview"
- Android: layout_width = "match_parent"
- Android: layout_height = "match_parent"
- Android: clickable = "true"
- Android: apikey = "0h91bcbpm7oya_1vun_tl0ygqqupnktt_ejfow"/>
Androdi: apikey is obtained from Google using the fingerprint of the keystore file.
1. debug key
As an android developer, two apikeys are generally required: Debug key and release key. The so-called debug key is used during program development. Because the android program requires a digital signature for use, it is too troublesome to run the program every time during development. Therefore, the system automatically uses debug during the development process. keystore signs the program, debug. keystrore is located in c: \ Documents and Settings \ <username> \ in Windows Server 2003 \. android.
To obtain the fingerprint of DEBUG. keystore, we need to use the following command:
[HTML]View
Plaincopy
- $ Keytool-list-alias androiddebugkey-keystore <path_to_debug_keystore>. keystore-storepass Android-keypass android
If it succeeds, the correct fingerprint of the keystore will be output. The format is as follows:
[HTML]View
Plaincopy
- 14: 5E: B2: 3A: 3f: de: 50: 61: 07: 2f: 39: 34: DB: 38: 57: dd
Open webpage
Http://code.google.com/android/maps-api-signup.html
Select the agree protocol check box and copy the fingerprint obtained above to obtain the apikey, as shown below:
Copy the key to the mapview in the XML file, and Google map can be used normally.
2. Release key
The method for applying the release key is the same as that for the debug key. The difference is that the release keystrore is not a debug. keystore file, but must be generated by itself. The command is as follows:
[HTML]View
Plaincopy
- $ Keytool-genkey-v-keystore my-release-key.keystore-alias alias_name-keyalg RSA-keysize 2048-validity 10000
You can use your own keystore to apply for an API key and write it to mapview.
In addition, the system should not automatically use DEBUG. keystore to sign the application, but the developer must manually sign the application. First, you need to export the project in unsigned mode, right-click the project-> Android tools-> export unsigned application package, such:
Use your own keystore file to sign the application:
[HTML]View
Plaincopy
- $ Jarsigner-verbose-sigalg md5withrsa-digestalg sha1-keystore my-release-key.keystore my_application.apk alias_name
The APK signature is an in-situ signature. It will overwrite the original APK and verify whether the signature is successful:
[HTML]View
Plaincopy
- $ Jarsigner-verify my_signed.apk
Finally, you need to compress the APK:
[HTML]View
Plaincopy
- $ Zipalign-V 4 your_project_name-unaligned.apk your_project_name.apk
References:
Http://developer.android.com/tools/publishing/app-signing.html
Https://developers.google.com/maps/documentation/android/mapkey#registering
Reprinted: http://blog.csdn.net/lrenjun/article/details/7717958