Dolphin MOVE SDK
SDK
1.x
1.x
  • Introduction
  • MOVE Services
  • MOVE SDK
    • Getting Started
      • MOVE Dashboard
      • Android
        • Installation
        • Quick Start
      • iOS
        • Installation
        • Quick Start
      • React Native
    • API Interface
      • Android
        • Initialization
        • Services
      • iOS
        • Initialization
        • Services
      • React Native
        • Initialization
        • Services
    • Models
      • MoveAuth
      • MoveConfig
      • MoveConfigurationError
      • MoveDeviceStatus
      • MoveSDKState
      • MoveTripState
      • MoveAuthState
      • Listeners/Callbacks
    • Appendix
      • Android
        • Token refresh
        • Permission Handling
        • Battery optimization
        • Notification Management
      • iOS
        • Permissions Handling
        • App Store
  • MOVE Backend
    • MOVE Timeline
    • MOVE State
    • MOVE Last Location
    • MOVE Generic Notifier
    • Open Api Specification
  • Changelog
    • Android
    • iOS
  • Data privacy (GDPR)
Powered by GitBook
On this page
  • Permission overview
  • Runtime permissions
  • Display over other apps
  • Background location
  1. MOVE SDK
  2. Appendix
  3. Android

Permission Handling

Description of required permissions, how to request and manage them.

PreviousToken refreshNextBattery optimization

Last updated 3 years ago

The library requires at least the following permissions to access Move services.

<uses-permission android:name="android.permission.INTERNET" />

Depending on the used services, different permissions are required. The following table gives an overview what's required:

Permission overview

Required permissions

Optional permissions

Mode of Transport

Driving

Bicycle

Walking

Driving Services

Distraction-Free-Driving (DFD)

Driving behaviour events (DBE)

Other services

Points of Interest

is not mandatory, but strongly recommended. Similarly for the optional Activity Recognition permission (Driving) - make sure to request this from the user, otherwise it will degrade the quality of the service.

More Information regarding the system permissions can be found here:

The required permissions must be granted before the services can be used. If any single required permission is missing, the entire SDK stops working. In case of any permission error, the SDKState callback will be triggered with an error state:

If there are permissions missing, the state is an object of type MoveSdkState.Error. The error state contains an error reason which can be any of the following:

  • Overlay (ErrorReason.PermissionMissing.Overlay)

  • Location (ErrorReason.PermissionMissing.Location)

  • Phone (ErrorReason.PermissionMissing.Phone)

  • Activity (ErrorReason.PermissionMissing.Motion) (since Android 10 )

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
 
    val sdkStatus = moveSdk.getSdkState()
    if (sdkStatus is MoveSdk.State.Error) {
        // Tell the SDK that we have fixed our issue
        sdkStatus.resolved()
    }
}

Runtime permissions

Display over other apps

Starting with Android 11, the user will only be taken to the settings overview screen, and the user needs to select the specific app itself.

val intent = Intent(
    Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
    Uri.parse("package:$packageName"))
startActivityForResult(intent, OVERLAY_REQUEST_CODE)

Background location

Since Android 10 there is an additional background location which should be also requested when asking for location permission. In Android 11 the user must go to the location settings of the app to grant the "Allow all the time" permission.

if (reason is ErrorReason.PermissionMissing.Location) {
    val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        // On Android Q both (foreground & background) permissions should be requested
        arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
    } else {
        arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
    }
    ActivityCompat.requestPermissions(this@MoveActivity, permissions, 0)
}

Full code example

The following shows an example which is used in our demo app.

val reason = errorState.reason
if (reason is ErrorReason.PermissionMissing) {
    if (reason is ErrorReason.PermissionMissing.Overlay) {
        requestOverlayPermission()
    } else if (reason is ErrorReason.PermissionMissing.Location) {
        val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            // On Android Q both (foreground & background) permissions should be requested
            arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
        } else {
            arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
        }
        ActivityCompat.requestPermissions(this@MoveActivity, permissions, 0)
    } else {
        val missingPermission = reason.permission
        ActivityCompat.requestPermissions(this@MoveActivity, arrayOf(missingPermission), 0)
    }
}
...
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
 
    if (requestCode == OVERLAY_REQUEST_CODE) {
        val moveSdk = yourApplication.getMoveSdk()
        val sdkStatus = moveSdk.getSdkState()
        if (sdkStatus is MoveSdkState.Error) {
            // Tell SDK that we have fixed our issue
            sdkStatus.resolved()
        }
    }
}

- improves trip recognition and classification considerably

,

,

The PermissionMissing error reason contains a string pertaining to the relevant permission of the Android Manifest, e.g. Manifest.permission.READ_PHONE_STATE. This permission string can be used to request dangerous permission directly as shown in the code example below. For more information about dangerous visit the .

In fact the SDK is not aware of permission changes, the developer can tell the SDK that the error is resolved. This can be done for example in .

In Android there are some which require a request during runtime. Keep in mind that those need to be defined in the manifest as well. Before init of the MOVE SDK, the proper permissions should have been already requested.

The overlay permission () ,which is required for distraction free driving, needs to be requested in a specific way. The user is lead to the app settings where the permission needs to be enabled.

official developer page
onRequestPermissionsResult()
permissions
SYSTEM_ALERT_WINDOW
https://developer.android.com/reference/android/Manifest.permission
MoveSdkState.Error
Background Location
ACCESS_FINE_LOCATION
ACTIVITY_RECOGNITION
ACCESS_FINE_LOCATION
ACTIVITY_RECOGNITION
ACTIVITY_RECOGNITION
READ_PHONE_STATE
SYSTEM_ALERT_WINDOW
ACCESS_FINE_LOCATION
Android App Info - Display over other apps