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
GetAssetCallback view source
Upon executing the code example provided above, your app's appearance will resemble the following snippet:
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:
-
Initialize the Asset Tracking SDK.
-
Create an asset profile.
-
Bind the asset profile to the device.
-
Start tracking the asset.
-
Receive asset tracking callbacks.
The following is a description of each step:
-
To initialize the Asset Tracking SDK, the activity calls the initialize() method with your API key.
-
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.
-
To bind the asset profile to the device, the activity calls the bindAsset() method with the asset ID.
-
To start tracking the asset, the activity calls the assetTrackingStart() method.
-
To receive asset tracking callbacks, the activity implements the AssetTrackingCallBack interface and overrides the following methods:
-
onLocationSuccess(): This method is called when the asset's location is updated.
-
onLocationFailure(): This method is called when the asset's location fails to be updated.
-
onTrackingStart(): This method is called when asset tracking is started.
-
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.