Last updated

OBH Android SDK

Overview

The OBH Android SDK enables seamless integration with OBH mobility services in Android applications. This guide covers installation, setup, and basic usage.


Installation Guide

Prerequisites

  • Android SDK version 29 or higher
  • GitHub account with access to the OBH private repository
  • Bluetooth Low Energy (BLE) capable device

Installation Steps

OBH android SDK is available on a private GitHub Maven repository. To be able to add it to your gradle dependencies, you will need an access to it.


Step 1: Generate a GitHub Token

  • Follow the instructions in the GitHub documentation to create a personal access token.
  • Make sure to configure the necessary permissions for the token.

When creating your Token, make sure to set at least the read permission to obh_android_sdk package.


Step 2: Configure Environment Variables

  • Add your GitHub credentials to the local.properties file:
gpr.user=YouGithubUsername
gpr.key=ghp_xxXXXxx
  • In your build.gradle file, load the local.properties file:
def localProperties = new Properties()
def localPropertiesFile = file('local.properties')
if (localPropertiesFile.exists()) {
   localPropertiesFile.withReader('UTF-8') { reader ->
       localProperties.load(reader)
   }
}

Step 3: Setup Repositories

  • Add the following repositories to your build.gradle or settings.gradle file:
repositories {
   google()
   mavenCentral()
   maven {
       url = uri("https://maven.pkg.github.com/obh-mobility/obh_android_sdk")
       credentials {
           username = localProperties.getProperty("gpr.user") ?: System.getenv("USERNAME")
           password = localProperties.getProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
       }
   }

   maven {
       url 'https://jitpack.io'
   }
}

Step 4: Configure minSdk

Configure your project minSdk version to at least 29. In most case, in build.gradle app file:

android {
  defaultConfig {
    minSdk 29
  }
}

Step 5: Add SDK Dependency

Add the SDK dependency to your project:

dependencies {
    implementation 'com.obhmobility:obhsdk:<sdk_version>'
    // Other dependencies here
}

Make sure to replace <sdk_version> with the version number you want to use.


Entrypoint

The entrypoint of the SDK is the class ObhSdk. This class have 2 main parameters :

  • apiBaseUrl: The base url of the OBH API. This is used to select a specific environment.
  • token: API access token

To change api infos of ObhSdk, use the method setApiValues.


Permissions

The OBH mount is connected with BLE. Lot of SDK functions need to access device BLE. This imply to ask user the BLE access permission (In addition to permission declarations).

This SDK do not ask these permissions. For example, this can be done with the following kotlin method:

private fun askPermission() {
    val locationPermission = ContextCompat.checkSelfPermission(
        applicationContext,
        Manifest.permission.ACCESS_COARSE_LOCATION
    )

    val scanPermission = ContextCompat.checkSelfPermission(
        applicationContext,
        Manifest.permission.BLUETOOTH_SCAN
    )

    if (locationPermission == PackageManager.PERMISSION_DENIED || scanPermission == PackageManager.PERMISSION_DENIED) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            ActivityCompat.requestPermissions(
                this,
                arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.BLUETOOTH_SCAN),
                2
            )
            return
        }
    }
}

For further information, please visit the android BLE permission documentation