Quickstart
Naurt Lite is a silent data collection SDK which accepts user data about a destination in JSON format, matches it with the current location data, and uploads it to Naurt's servers to process it into building entrance and parking spot locations that can be accessed through our POI API. Before you begin, ensure you have a valid API key. If you don't, no worries. You can sign up for a free account and key on our dashboard.
Project Configuration
Naurt's minimum supported API level is 16 which is Android 4.1 (Jelly Bean). Your project's build.gradle file should contain a "minSdkVersion" of 16 or above.
android {
defaultConfig {
minSdkVersion 16
}
}
While you're in the build.gradle file, Naurt also needs to be added as a dependency. First add mavenCentral()
to your repositories
repositories {
mavenCentral()
}
And then the Naurt Lite can be added as a dependency.
dependencies {
implementation "com.naurt.sdk:lite:0.0.5"
}
To view change logs or manually include Naurt Lite in your project, visit our Github.
App permissions
As Naurt accesses the phone's Network and GPS location services, you'll need to add the corresponding permissions to your AndroidManifest.xml file to ensure Naurt Lite works as expected.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
You will also need the user to grant location permissions before starting Naurt. If you do not already have this logic in your application, you can use the following example to check for the granted permission and only initialise Naurt if it has been granted.
private val LOCATION_PERMISSION_REQUEST_CODE = 1001
if (!this.hasLocationPermission()) {
this.requestLocationPermission()
} else{
// Start Naurt!
}
// Check if the app has permission to access location
private fun hasLocationPermission(): Boolean {
val permissionStatus = ContextCompat.checkSelfPermission(
this,
ACCESS_FINE_LOCATION
)
return permissionStatus == PackageManager.PERMISSION_GRANTED
}
// Request location permission from the user
private fun requestLocationPermission() {
ActivityCompat.requestPermissions(
this, arrayOf(ACCESS_FINE_LOCATION),
LOCATION_PERMISSION_REQUEST_CODE
)
}
// Handle the result of the permission request
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d("Naurt", "I have the permissions!")
// Start Naurt
} else {
Log.d("Naurt", "I haven't got the permissions!")
// Don't start Naurt
}
}
}
Instantiating Naurt
First, begin by importing the NaurtLite class
import com.naurt.sdk.NaurtLite
Naurt Lite then requires a valid Naurt API key and the application's context.
val naurtLite = NaurtLite("<API_KEY_HERE>", applicationContext as Context)
Instantiation should be carried out within the onCreate() method of the app, though it's important the user has granted location permissions first otherwise Naurt Lite will throw an exception.
Once Naurt has been created, validation will be attempted and, once successful, Naurt will begin collecting the location data required to log building entrance and parking locations. Please see Points Of Interest for more information.
Disabling Naurt
When you're finished using Naurt Lite and want to close the app, call the onDestroy method. This will clean up any internal processes and listeners created by Naurt. We recommend doing this within the onDestroy method of your app.
naurtLite.onDestroy()
Example Application
We also have an example application which combines the above concepts into a full app.
It can be found on our GitHub here.
Background tracking
By default, Naurt Lite does not automatically track when its parent app is in the background. To do this, Naurt Lite should be included within a foreground service, or the background tracking permission should be engaged and enabled.