Additional Configuration
Add the API Key
Add your API key to the project by opening the AndroidManifest.xml file and adding a <meta-data> element inside the <application> tag, as shown below:
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="Please enter your API key"/>
……
</application>Declare the Location Service Component
If your project uses the AMAP Location SDK, you must declare the location service component in AndroidManifest.xml to ensure proper functionality. Add the following <service> element inside the <application> tag:
<service android:name="com.amap.api.location.APSService"/>Configure Permissions
For Android 6.0 (API level 23) and higher, see the Android 6.0 Permissions section.
Add the following permissions to your AndroidManifest.xml file:
<!-- Required: Allows network access -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required for real-time navigation: Allows precise location access -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required for real-time navigation: Allows approximate location access -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Required for network-based positioning (when GPS is unavailable): Allows access to network state -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required for network-based positioning (when GPS is unavailable): Allows access to Wi-Fi network information -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Required for network-based positioning (when GPS is unavailable): Allows monitoring of Wi-Fi state changes -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- Required for background location or continuous navigation: Allows location access in the background -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- Used to request A-GPS module access for faster satellite positioning -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<!-- Used to display a Bluetooth connection reminder on the navigation component page when a Bluetooth device is connected; developers can use the Bluetooth channel for TTS playback after the connection is established -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- Used to keep the screen on during navigation -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- Allows writing to device cache for troubleshooting -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />Privacy Compliance
Privacy Compliance API
The following APIs handle privacy policy compliance for the Navigation SDK:
/**
* Sets whether the privacy policy is included and displays a user consent dialog.
* Must be called before AMapNavi.getInstance(context).
*
* @param context The application context
* @param isContains Whether the privacy policy includes the AMap privacy policy (true = yes)
* @param isShow Whether to display a dialog informing the user about the privacy policy (true = yes)
* @since 8.1.0
*/
public static void updatePrivacyShow(Context context, boolean isContains, boolean isShow);/**
* Sets whether the user has agreed to the privacy policy.
* Must be called before AMapNavi.getInstance(context).
*
* @param context The application context
* @param isAgree Whether the user has agreed to the privacy policy (true = agreed)
* @since 8.1.0
*/
public static void updatePrivacyAgree(Context context, boolean isAgree);Compliance Check Before Initialization
Call the privacy compliance APIs before invoking AMapNavi.getInstance:
NaviSetting.updatePrivacyShow(context, true, true);
NaviSetting.updatePrivacyAgree(context, true);Exception Handling During Initialization
Wrap the AMapNavi.getInstance call in a try-catch block to handle exceptions:
try {
mAMapNavi = AMapNavi.getInstance(getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}Null Check Before Use
Always check for null before using mAMapNavi:
if (mAMapNavi != null){
// TODO
}Personal and Device Information Collection
/**
* Sets whether to allow collection of personal and device information.
* @param collectEnable true to allow collection, false to disallow
*/
AMapUtilCoreApi.setCollectInfoEnable(boolean collectEnable);Code Obfuscation
When generating a signed APK with code obfuscation enabled, add the following rules to your proguard-rules.pro file. If warnings appear, add -dontwarn statements for the affected packages.
# 2D Map SDK:
-keep class com.amap.api.maps2d.**{*;}
-keep class com.amap.api.mapcore2d.**{*;}
# 3D Map SDK (before V5.0.0):
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.amap.mapcore.*{*;}
-keep class com.amap.api.trace.**{*;}
# 3D Map SDK (V5.0.0 and later):
-keep class com.amap.api.maps.**{*;}
-keep class com.autonavi.**{*;}
-keep class com.amap.api.trace.**{*;}
# Location SDK:
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}
# Search SDK:
-keep class com.amap.api.services.**{*;}
# Navigation SDK (before V7.3.0):
-keep class com.amap.api.navi.**{*;}
-keep class com.alibaba.idst.nls.** {*;}
-keep class com.nlspeech.nlscodec.** {*;}
-keep class com.google.**{*;}
# Navigation SDK (V7.3.0 and later):
-keep class com.amap.api.navi.**{*;}
-keep class com.alibaba.mit.alitts.*{*;}
-keep class com.google.**{*;}
# Navigation SDK (V8.1.0 and later):
-keep class com.amap.api.navi.**{*;}
-keep class com.alibaba.idst.nui.* {*;}
-keep class com.google.**{*;}Additional Configuration
Setting the Country Code
public static void updateCountryCode(String var0) {}Setting RTL Mode
public static void setRtlEnabled(boolean b) {}
public static boolean isRtlEnabled() {}