• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Get AssetTrackingCallback

This example will guide you through the following steps:

  • Initialization with Default Configurations: Learn how to set up the SDK with default configuration values, simplifying the integration process.

  • Creating, Binding, and Initiating Tracking for a Simple Asset: Discover how to create an asset, bind it to your application, and commence tracking. This sequence of actions enables you to monitor asset locations effectively.

  • Receiving AssetTrackingCallback in Your Activities: Gain insight into handling AssetTrackingCallback within your activities, ensuring that you can seamlessly manage and respond to asset-tracking events.

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

activity_get_asset_callback.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.GetAssetCallback">
10
11 <LinearLayout
12 android:layout_width="wrap_content"
13 android:layout_height="wrap_content">
14
15 <Button
16 android:id="@+id/callback_start_tracking"
17 android:layout_width="wrap_content"
18 android:layout_height="wrap_content"

GetAssetCallback view source

1class GetAssetCallback : AppCompatActivity(), AssetTrackingCallBack {
2 private lateinit var startTrackingButton: Button
3 private lateinit var stopTrackingButton: Button
4 private lateinit var trackingStatusView: TextView
5 private lateinit var locationInfoView: TextView
6
7 var permissionsManager: LocationPermissionsManager? = null
8 private var assetId = ""
9
10 override fun onCreate(savedInstanceState: Bundle?) {
11 super.onCreate(savedInstanceState)
12 setContentView(R.layout.activity_get_asset_callback)
13
14 // initialize the Asset Tracking SDK
15 initialize("PUT YOUR API KEY HERE")
16 assetTrackingAddCallback(this)
17
18 createAndBindAsset()

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 receive asset tracking callbacks using the Asset Tracking SDK. The activity has the following main steps:

  1. Initialize the Asset Tracking SDK.

  2. Create an asset profile.

  3. Bind the asset profile to the device.

  4. Start tracking the asset.

  5. Receive asset tracking callbacks.

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 profile, 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 profile to the device, the activity calls the bindAsset() method with the asset ID.

  4. To start tracking the asset, the activity calls the assetTrackingStart() method.

  5. To receive asset tracking callbacks, the activity implements the AssetTrackingCallBack interface and overrides the following methods:

    1. onLocationSuccess(): This method is called when the asset's location is updated.

    2. onLocationFailure(): This method is called when the asset's location fails to be updated.

    3. onTrackingStart(): This method is called when asset tracking is started.

    4. onTrackingStop(): This method is called when asset tracking is stopped.

The activity also includes a few helper functions:

  • createAndBindAsset(): This function creates an asset profile, binds it to the device, and starts tracking the asset.

  • checkPermissionsAndStartTracking(): This function checks for location permissions and starts tracking the asset if they are granted.

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


Have Questions ?