• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Simple Asset Tracking

This example provides step by step guidance on:

  1. Initializing Configurations with Default Values: Learn how to set up the SDK with default configuration settings, ensuring a straightforward integration process.

  2. Creating and Binding a Simple Asset: Discover how to create and bind an asset within your application, enabling you to associate assets with your tracking system.

  3. Starting Tracking and Uploading Location Data with Default Values: Gain insights into how to initiate tracking and the automatic uploading of location data using default parameters, simplifying the process of monitoring asset locations.

For all code examples, refer to Asset Tracking Android Code Examples

activity_simple_tracking.xml view source

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 android:orientation="vertical"
8 android:padding="10dp"
9 tools:context=".codeexample.SimpleTrackingExample">
10
11 <Button
12 android:id="@+id/start_tracking_simple"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:text="@string/start_tracking"
16 />
17
18 <TextView

SimpleTrackingExample view source

1class SimpleTrackingExample : AppCompatActivity() {
2 private lateinit var startTrackingButton: Button
3 private lateinit var trackingStatusView: TextView
4 private lateinit var assetIdView: TextView
5
6 var permissionsManager: LocationPermissionsManager? = null
7 private var assetId = ""
8
9 override fun onCreate(savedInstanceState: Bundle?) {
10 super.onCreate(savedInstanceState)
11 setContentView(R.layout.activity_simple_tracking)
12 initView()
13
14 // initialize the Asset Tracking SDK
15 initialize("PUT YOUR API KEY HERE")
16
17 createAsset()
18 }

Upon executing the code example provided above, your app's appearance will resemble the following snippet:

docs-image

Code Highlights

The above code snippet is for an Android activity that demonstrates how to start tracking an asset using the Asset Tracking SDK. The activity has the following main steps:

  1. Initialize the Asset Tracking SDK.

  2. Create an asset.

  3. Bind the asset to the device.

  4. Check for location permissions and start tracking.

The following is a description of each step:

  1. To initialize the Asset Tracking SDK, the activity calls the initialize() method with your API key.

  2. To create an asset, the activity creates an AssetProfile object and sets its properties. The AssetProfile object specifies the asset's custom ID, name, description, and attributes.

  3. To bind the asset to the device, the activity calls the bindAsset() method with the asset ID.

  4. To check for location permissions and start tracking, the activity calls the checkPermissionsAndStartTracking() method. This method first checks if all location permissions are granted. If they are, the method starts tracking the asset. If they are not granted, the method shows a dialog to the user asking them to grant the permissions.

The code snippet also includes a few helper functions:

  • showLocationServiceOffDialog(): This function shows a dialog to the user if location services are disabled.

  • startTracking(): This function starts tracking and uploading the location data of the asset.

Have Questions ?