Android Baidu Map Application Development Basic Knowledge _android

Source: Internet
Author: User
Tags certificate fingerprint sha1 system log

I. Overview
This chapter first to some interesting Baidu map application examples, and then chapter detailed introduction to use C # to develop the Android app of the basic technology.
This chapter with Baidu website January 2016 released map API (3.7.1 version) as an example, demonstrates how to use C # and VS2015 to write Baidu map application, these sample programs can be run in the Android 6.0 x86 simulator, can also be published to Android More than 4.0 version of the phone to test the actual operation of the effect.
1, download the demos provided by the official website
First visit the following URL: http://developer.baidu.com/map/
After opening the page, select "Development" à "andoid development" under the 1th "Android Map SDK", click on the page "Related downloads", the following interface will appear:

Click "Custom Download", in the pop-up interface, in addition to navigation features, all the other selected, and then download it to the computer, and extract to a folder, for subsequent steps to use it.
2, the use of Gaxaxy_api23_x86 simulator to observe the results of the operation
to solve the problem of mapview using hardware acceleration, Baidu provides a Texturemapview control that requires modifying the emulator's developer options when rendering a map using this control.
To use Texturemapview display Baidu Map, you need to meet the following conditions:
• Change all Mapview in the official example to be rendered using the Texturemapview control.
• Modify the emulator developer option to allow the emulator to "Force GPU rendering" (as shown in the following illustration).

These two conditions are satisfied, Baidu Map can be displayed smoothly.
Well, there's no need to put up with this particular "slow" arm simulator without hardware acceleration, and the following example will continue to be demonstrated with the x86 simulator with hardware acceleration.
Of course, can also be directly with the mobile phone debugging (this is the recommended debugging method, mobile phone connected to the computer can be directly in the debug right of the Drop-down box to see the phone's options, this way to debug the map application is more realistic.) However, because of the trouble of the phone to debug screenshots, so here is directly with the simulator to demonstrate.

Second, create bdmapv371bindinglib solution
Solution and project name: Bdmapv371bindinglib
Template: Bindings Library (Android)
The purpose of creating a binding library is to automatically convert all. jar files of the Baidu Map SDK version 3.7.1 to the. cs file and generate the corresponding. dll file, after which the generated. dll file can be referenced in the application project.
This is also the most common way to convert. jar files to. cs files.
1. Add jar file
Copy the following files to the project's Jars folder and change the Build Action property of these files to "Embeddedjar".
Baidulbs_android.jar
Indoorscapealbumplugin.jar
2, add the latest stable version of the XAMARIN.ANDROID.SUPPORT.V4 reference
Right-click the "Reference" à "management NuGet package", add the latest stable version of XAMARIN.ANDROID.SUPPORT.V4 reference, I added is xamarin.android.support.v4.23.1.1.0.
3. Modify Metadata.xml File
Open the Metadata.xml file under the Transforms folder and change it to the following:

<metadata> <attr path= "/api/package[@name = ' Com.baidu.mapapi ']/class[@name = ' versioninfo ']/field[@name = ' Version_info '] "name=" Managedname ">VersionInfoString</attr> <attr path="/api/package[@name = ' Com.baidu.platform.comapi.map ']/class[@name = ' a ']/field[@name = ' A '] ' name= ' managedname ' >aVar</attr> < attr path= "/api/package[@name = ' Com.baidu.platform.comapi.map ']/class[@name = ' B ']/field[@name = ' B '] ' name= ' Managedname ">bVar</attr> <attr path="/api/package[@name = ' com.baidu.location ']/class[@name = ' address '] /field[@name = ' address '] "name=" Managedname ">AddressString</attr> <attr path="/api/package[@name = ' Com.baidu.mapapi.cloud ']/class[@name = ' versioninfo ']/field[@name = ' version_info '] ' name= ' managedname ' > versioninfostring</attr> <attr path= "/api/package[@name = ' Com.baidu.mapapi.radar ']/class[@name = ' Versioninfo ']/field[@name = ' version_info '] "name=" Managedname ">VersionInfoString</attr> <attr path="/ api/package[@name = ' com. Baidu.mapapi.search.core ']/class[@name = ' g '] "name=" obfuscated ">false</attr> <attr path="/api/package [@name = ' com.baidu.mapapi.search.district ']/class[@name = ' districtsearch '] ' name= ' managedname ' >districtsearchs </attr> <attr path= "/api/package[@name = ' COM.BAIDU.PANO.PLATFORM.COMAPI.A ']/class[@name = ' A ']" name= " obfuscated ">false</attr> <attr path="/api/package[@name = ' com.baidu.location ']/class[@name = ' Locationclientoption ']/field[@name = ' Mlocationmode '] "name=" visibility ">public</attr> <attr path="/api /package[@name = ' com.baidu.mapapi.a.a ']/class[@name = ' A '] ' name= ' obfuscated ' >false</attr> </metadata

 >

4. Add BaiduMapOptions.cs File
Add the file under the Additions folder, and then change it to the following:

Namespace Com.Baidu.Mapapi.Map
{public
  partial class baidumapoptions
  {public
    baidumapoptions () {}
  }
}

The purpose of this file is to provide a constructor without parameters, and if you do not add the file, you cannot create an instance of Baidumapoptions directly in the Demos project in the subsequent section (this is not intended to be used).
5. Generate DLL file
Right-click the project name, select Build, and you should see the compilation success in the Output window:
========== All regenerated: 1 successes, 0 failures, 0 ========== skipped
As a result, the BdMapV371BindingLib.dll is successfully generated under the Bin\Debug folder, which can then be referenced in the sample project.

III. Create a Bdmapv371demos solution and obtain a development key
Solution and project name: Bdmapv371demos
Template: Blank App (Android)
The development of Baidu Map application, the need to first in Baidu official online application for a development key, Baidu's development key by "sha1+ package name" Composition, this is to make a project only corresponding to an application key. When the key application is successful, you can use the Baidu Map API in the corresponding project.
1. Modify Androidmanifest.xml File
Modify the file for the Bdmapv371demos project and change it to the following:

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/" Android "package=" Bdmapv371demos.bdmapv371demos "android:versioncode=" 1 "android:versionname=" 1.0 "Android: installlocation= "Auto" > <uses-sdk/> <application android:label= "Bdmapv371demos" @style Mycustomtheme "> <meta-data android:name=" Com.baidu.lbsapi.API_KEY "android:value=" Your Application key "/> <service
  Android:name= "COM.BAIDU.LOCATION.F" android:enabled= "true" android:process= "remote"/> </application> <uses-permission android:name= "Android.permission.WAKE_LOCK"/> <uses-permission android:name= " Com.android.launcher.permission.READ_SETTINGS "/> <uses-permission android:name=" android.permission.WRITE_ SETTINGS "/> <!--access network, network positioning needs to access the Internet--> <uses-permission android:name=" Android.permission.INTERNET "/> ;! --this permission is used for network positioning--> <uses-permission android:name= "Android.permission.ACCESS_coarse_location "/> <!--to access WiFi network information, WiFi information will be used for network positioning--> <uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE "/> <!--obtain carrier information to support the interface for providing carrier information--> <uses-permission Android:name = "Android.permission.ACCESS_NETWORK_STATE"/> <!--this permission is used to obtain WiFi access and WiFi information is used for network positioning--> < Uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE"/> <!--used to read the phone's current status--> < Uses-permission android:name= "Android.permission.READ_PHONE_STATE"/> <!--write to the extended storage, write data to the expansion card for writing offline location data--> &
  Lt;uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <!--SD card read access, user writes offline location data--> <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!--allows applications to read low-level system log files- > <uses-permission android:name= "Android.permission.READ_LOGS"/> <uses-permission android:name= " Android.permission.ACCESS_SURFACE_FLINGER "/> <!--<uses-permission android:name=" AndrOid.permission.ACCESS_FINE_LOCATION "/> <uses-permission android:name=" Android.permission.LOCATION_HARDWARE "/> <uses-permission android:name= android.permission.SET_ANIMATION_SCALE"/>--> <supports-screens A Ndroid:anydensity= "true" android:largescreens= "true" android:normalscreens= "false" android:resizeable= "true"

 Android:smallscreens= "true"/> </manifest>

2, the operation of the project to get SHA1
Press the <F5> key to run the project and locate the following line in the Output window:
D/auth info (3210): Mcode: "..." bdmap361test.bdmap361test
Where, before the semicolon "..." is SHA1, copy it for the next application key.
Description: When creating another solution and project, as long as your development environment is unchanged, the debug mode of the SHA1 or this value (this value is not related to which project, It's about debug.keystore files, so it's a good idea to keep this SHA1 in a separate document so that you can use it later to request multiple development keys.
Of course, since this step has not yet completed the 2nd step of the key request, the map is still not visible.
In fact, if you look at the output window a little bit, you'll find that when you press the <F5> key to run, the system will automatically perform the commands described below. Or, these steps are automatically done by the system and do not need to be done. The reason why these commands are explained here is to help you understand how it gets SHA1 and automatically displays it for you to use:
For Windows operating systems, by default, the KeyStore for application signing can be found in the following location: Xamarin.android Debug Version.
C:\users\[username]\appdata\local\xamarin\mono for Android\debug.keystore
Information from the KeyStore is available through the Keytool command provided by the JDK. For Windows systems, the location of the Keytool is: C:\Program Files (x86) \java\jdk1.7.0_79\bin Keytool.exe.
The use in VS2015 is (you do not need to configure the environment variable): Click "Tools" à "Android" à "android Adb command Prompt" to enter the command line mode.
In command line mode, you can run the Keytool tool using the following command:
Keytool-list-v-keystore [Store FILENAME]-alias [key NAME]-storepass [store PASSWORD]-keypass [key PASSWORD]
The specific command you type is (note [USERNAME] should be replaced with the actual name):
C:\
Cd\users\[username]\appdata\local\xamarin\mono for Android
Keytool-list-v-keystore Debug.keystore-alias androiddebugkey-storepass android-keypass Android
At this point you will see the following in the console window:
Alias: Androiddebugkey

Serial number:...... (The specific values are omitted here)

Valid Start Date: ... (The specific values are omitted here)

Due Date: ... (The specific values are omitted here)

Certificate fingerprint:

MD5: ... (The specific values are omitted here)

SHA1: ... (The specific values are omitted here)

SHA256: ... (The specific values are omitted here)

Signature Algorithm Name: Sha256withrsa

Version: 3

Extended

......

3, access to the official website to obtain development key
Enter Baidu's official website (http://developer.baidu.com/map/), select "Development" à "andoid development" under the 1th "Android Map SDK", and then click on the page "Request Key", select " Enter the new key application system and enter the following information:
Application Name: Bdmapv371demos

Application Type: Android SDK

Digital signature (SHA1):

Package Name: Bdmapv371demos.bdmapv371demos

For a C # project, the package name entered here is actually the solution name. Project name, and there is no requirement for all lowercase letters.

Paste the SHA1 you copied in the previous step into the text box to the right of digital signature (SHA1).

Click the Submit button to complete the key request.
4, the application of the key to fill in the configuration file
Modify the Androidmanifest.xml file and fill in the application with the key you just requested.
When you apply for a new key for a new project later, the SHA1 value will not change as long as the development environment is unchanged. When you apply for a new key later, just fill in the SHA1 value.
You can then step through the examples that are described later in this chapter.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.