Setting up your Android Studio Project

Setting up your Android Studio Project

1 Add NAO SDK as a dependency

  • Add the following line to your build.gradle so your project fetches the NAO SDK from JCenter or Maven Central:
    dependencies {
        implementation 'eu.polestar:naosdk:4.+' // final '+' ensures you are using the latest version in the 4.0 series
    }

Note: by default your android project should already have that line in the project build.gradle:

allprojects {
    repositories {
        jcenter()
    }
}

Add Pole Star maven url in your project gradle:

maven { url "https://dist.nao-cloud.com/android/maven/" }

2 Set-up Android Services

  • Create an Android Service class in the package of your choice by extending com.polestar.naosdk.managers.NaoServiceManager. In that new class, you need not override any methods as in the example below. The purpose of that set-up is to allow different apps on the same device to integrate NAO SDK in isolation.
    package your.package;
    import com.polestar.naosdk.managers.NaoServiceManager;
    public class MyNaoService extends NaoServiceManager {}
  • Declare the Android service you created above by adding the following lines to the <application> block of your AndroidManifest.xml: do not add a new process for this service.
    <service android:name="your.package.MyNaoService" />
  • Optionally, declare AndroidGeofencingService to receive wake-up notifications when arriving on-site by adding the following snippet to AndroidManifest.xml (still in the <application> block)
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <service
        android:name="com.polestar.naosdk.controllers.AndroidGeofencingService"
        android:exported="true"
        android:label="@string/app_name" />
    <service
        android:name="com.polestar.models.GeofenceTransition"
        android:exported="true"
        android:label="@string/app_name"
        android:process=":geofencing" />

3 Declare Permissions

  • Add additional permissions to your application if they are not already listed in AndroidManifest.xml:
    <!-- NORMAL PERMISSIONS: explicit user confirmation not needed -->

    <!-- Internet connectivity (for data synchro) -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Used for BLE-based location -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

    <!-- Used for WiFi-based location -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

    <!-- SENSITIVE PERMISSIONS: user will be prompted for acceptation by Android OS -->

    <!-- access to OS Loc / GPS and BLE sensor (since Android 6)-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

     <!-- Add permission WRITE_EXTERNAL_STORAGE (limited to sdk<=18) -->
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="18" />

  • Note that on Android 6 and later, it’s not enough to declare permissions, your app is responsible for requesting them explicitly from the user.

 

4 Mutual dependencies

    • Related Articles

    • Android 12

      Intro Android 12 introduced new features and behaviors, from permissions to security, that affect directly the NAO® SDK. All the changes are described on Android 12’s documentation. NAO® SDK Release 21.02 (v4.10.x) will still work as expected with ...
    • Android

      NAOMAPSDK is a mobile map tool that allows developers to integrate indoor maps into Android and iOS applications using map data from NAO Cloud. This SDK simplifies the process of adding indoor mapping functionality to mobile apps, making it easier ...
    • Android 8

      Android 8.0 (API level 26) introduces behavior changes as well as new features and APIs. The key changes that impact NAO SDK are Android background execution limits. If you are using NAO SDK only in a user-app interactive way, there will not be much ...
    • Android 11

      Location Permissions If your app targets Android 11: Like Android 10, you need location permission called ACCESS_BACKGROUND_LOCATION to allow location information even if the app is in the background. If you request a foreground location permission ...
    • Android 9

      Android 9 (API level 28) introduces a number of changes to the Android system. The following behavior changes apply to all apps when they run on the Android 9 platform, regardless of the API level that they are targeting. All developers should review ...