Document Location SDK for Android Guides Utility Tools Android 9 Permissions

Android 9 Permissions

/**
 * Enables background location.
 * <font color="red"><b>Note:</b></font>
 * If you set target >= 28, you need to add the android.permission.FOREGROUND_SERVICE permission.<br/>
 * If your app needs to run on Android Q, you need to add the android:foregroundServiceType="location" 
 * attribute to APSService, for example:
 * &lt;service
 *         android:name="com.amap.api.location.APSService"
 *         android:foregroundServiceType="location"&#x2F;&gt;
 * <p>
 * This is mainly to address the background location restrictions on Android 8.0 and above. 
 * Once enabled, a notification will be displayed in the notification bar. If your app already 
 * has a foreground service notification, you do not need to enable this.<br>
 * <font color="red"><b>Note:</b></font> Enabling background location only grants the ability 
 * to locate in the background. To start locating, call {@link #startLocation()}.<br>
 * Tip: If there are multiple AMapLocationClient instances in your app, you only need to enable 
 * background location for one of them. Enabling it multiple times will still only show one 
 * notification.
 * </p>
 *
 * @param notificationId  Notification ID, recommended to be unique within the app; cannot be 0
 * @param notification    Custom notification. You can customize the Notification based on your 
 *                        business requirements and pass the created Notification object; cannot be null
 * @since 3.8.0
 */
public void enableBackgroundLocation(int notificationId, Notification notification)
<!-- Required if background location is enabled via our method, or if the app uses a foreground 
     service internally, and the target SDK version is Android 9 (API level 28) or above -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>