LogoLogo
Useful links
  • Home
  • Product guides
  • API
  • SDKs
  • Overview
  • First steps
  • ANDROID
    • Getting Started with the SDK
    • Standalone Modules
      • Document Detector
        • Release Notes
        • Current Version
        • Requirements
        • Gradle Dependencies
        • Gradle Source Code
        • Setting up the SDK
          • Setting properties
          • Capture Stages
          • Messages Settings
          • Customization
          • Security Settings
          • Detection Steps
          • Upload Mode
          • Advanced Settings
            • Proxy configuration
            • Preview configuration
        • Start Document Detection
        • Source Code
        • Google security form
        • Reduce SDKs size
        • SDKs response
        • References
        • FAQ
      • Face Liveness
        • Release Notes
        • Current Version
        • Requirements
        • Gradle Dependencies
        • Gradle Source Code
        • SDK Lifecycle
        • Building the SDK
        • Start Liveness Verification
        • Source Code
        • References
        • Advanced Features
        • FAQ
      • Face Authenticator
        • Release Notes
      • Smart Auth
        • Release Notes
        • Current Version
        • Requirements
        • Gradle Dependencies
        • Gradle Source Code
        • Permissions
        • SDK Lifecycle
        • Building the SDK
        • Start Smart Authentication
        • Source Code
        • References
        • FAQ
      • Face Liveness (deprecated)
        • Release Notes
  • iOS
    • Getting Started with the SDK
    • Standalone Modules
      • Document Detector
        • Release Notes
        • Current Version
        • Requirements
        • Installing the SDK
        • Setting up the SDK
          • Setting properties
          • Messages Settings
          • Customization
          • Detection Steps
          • Upload Mode
          • Advanced Settings
            • Proxy configuration
            • Preview configuration
        • Start Document Detection
        • References
        • FAQ
      • Face Liveness
        • Release Notes
        • Installation
        • Current Version
        • Requirements
        • SDK Lifecycle
        • Building the SDK
        • Start Liveness Verification
        • Source Code
        • References
        • FAQ
      • Face Authenticator
        • Release Notes
        • Installation
        • Current Version
        • Requirements
        • Building the SDK
        • Start the SDK
        • References
        • FAQ
      • Smart Auth
        • Release Notes
        • Installation
        • Current Version
        • Requirements
        • SDK Lifecycle
        • Building the SDK
        • Start Smart Authentication
        • Source Code
        • References
        • FAQ
      • Face Liveness (deprecated)
        • Release Notes
  • REACT NATIVE
    • Standalone Modules
      • Document Detector
        • Release Notes
        • Current Version
        • Requirements
        • Installation
        • Hooks
        • Start Document Verification
        • Source Code
        • TypeScript References
        • Customizing Style
        • FAQ
      • Face Liveness
        • Release Notes
        • Current Version
        • Requirements
        • Installation
        • Hooks
        • Start Liveness Verification
        • Source Code
        • TypeScript References
        • FAQ
      • Face Authenticator
        • Release Notes
        • Current Version
        • Requirements
        • Installation
        • Hooks
        • Start Authentication Verification
        • Source Code
        • TypeScript References
        • FAQ
      • Smart Auth
        • Getting started
        • Release notes
        • Using Native Modules
          • Requirements
          • Gradle Source Code
          • Podfile Source Code
          • Native Module Android
          • Native Module iOS
          • Import Native Modules
          • Source Code
          • TypeScript References
          • FAQ
        • Using Expo Modules
          • Requirements
          • Create Local Expo Module
          • Gradle Source Code
          • Podspec Source Code
          • Native Module Android
          • Native Module iOS
          • Import Expo Modules
          • Source Code
          • TypeScript References
          • FAQ
  • WEB (JAVASCRIPT)
    • Standalone Modules
      • Document Detector
        • Getting started
        • SDK builder options
          • Analytics
          • Appearance
          • Messages
        • SDK methods
        • Event listeners
        • Customization
        • Release notes
      • Face Liveness
        • Customization
        • Release notes
      • Face Authenticator
        • Customization
        • Release notes
      • Smart Auth
        • SDK errors
        • Customization
        • Release notes
LogoLogo

2025 © Caf. - All rights reserved

On this page
  1. ANDROID
  2. Standalone Modules
  3. Smart Auth

Permissions

Guide to Implementing and Handling Runtime Permissions for Location in Your Android SDK (CafSmartAuth)

In Android, certain permissions, especially those related to sensitive data like location, require runtime approval from users. This guide explains how to check and request location permissions programmatically in your SDK, CafSmartAuth, using the checkPermissionStatus function provided below.


Why CafSmartAuth Requires Location Permissions

CafSmartAuth requires access to the user’s location as part of its fraud prevention features, ensuring an additional layer of security by verifying location-based information. Android distinguishes between two types of location access, allowing users to control the precision of the location data they share:

  • ACCESS_FINE_LOCATION: Required for precise location information from GPS, which is essential for detecting potentially fraudulent activities with high accuracy.

  • ACCESS_COARSE_LOCATION: Provides approximate location data based on Wi-Fi and cellular networks, suitable for basic location checks.

With these permission levels, users can provide the minimum required access for fraud prevention, while CafSmartAuth ensures compliance with Android's data privacy practices.


Step-by-Step: Adding and Using checkPermissionStatus

  1. Add Permissions to the Manifest

    In your app's AndroidManifest.xml, include both location permissions:

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

    These manifest declarations allow the app to request these permissions but don’t automatically grant them.

  2. Define a Request Code Constant

    To identify the permission request, use a constant for the request code:

     companion object {
         private const val REQUEST_CODE = 1234
     }
  3. Create and Use checkPermissionStatus to Handle Permissions

    The checkPermissionStatus function checks if permissions have been granted and, if not, requests them from the user. This is essential for compliance with Android’s runtime permission model introduced in Android 6.0 (API level 23).

    Here’s the code and an explanation of how it works:

     private fun checkPermissionStatus() {
         // Check for ACCESS_FINE_LOCATION permission
         if (ContextCompat.checkSelfPermission(
                 this,
                 Manifest.permission.ACCESS_FINE_LOCATION
             ) != PackageManager.PERMISSION_GRANTED
         ) {
             // Request the ACCESS_FINE_LOCATION permission if it hasn't been granted
             ActivityCompat.requestPermissions(
                 this,
                 arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                 REQUEST_CODE
             )
         }
    
         // Check for ACCESS_COARSE_LOCATION permission
         if (ContextCompat.checkSelfPermission(
                 this,
                 Manifest.permission.ACCESS_COARSE_LOCATION
             ) != PackageManager.PERMISSION_GRANTED
         ) {
             // Request the ACCESS_COARSE_LOCATION permission if it hasn't been granted
             ActivityCompat.requestPermissions(
                 this,
                 arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION),
                 REQUEST_CODE
             )
         }
     }
    • ContextCompat.checkSelfPermission: This checks if the app has a specific permission. If the permission isn’t granted, it returns PackageManager.PERMISSION_DENIED.

    • ActivityCompat.requestPermissions: Requests the specified permission(s) from the user, displaying a system dialog for approval.

  4. Handle the Permission Result

    When requesting permissions, you can handle the result in onRequestPermissionsResult to manage user responses appropriately.

     override fun onRequestPermissionsResult(
         requestCode: Int,
         permissions: Array<out String>,
         grantResults: IntArray
     ) {
         super.onRequestPermissionsResult(requestCode, permissions, grantResults)
         if (requestCode == REQUEST_CODE) {
             if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                 // Permission was granted.
             } else {
                 // Permission was denied.
             }
         }
     }
  5. Call checkPermissionStatus at the Right Time

    You might want to call checkPermissionStatus within onResume or when location functionality is triggered, ensuring permissions are checked before they’re needed.


Last updated 2 months ago