• Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us
  • Home
  • Resources
    • User Guides
    • Concepts Articles
    • API References
    • Client Libraries & SDKs
    • Product Updates
  • FAQs
    • General
    • IoTConnect
      • Device Rules
      • Devices
      • Settings
      • Device Commands
      • Device Templates
      • Device Firmware
      • Device Onboarding
    • Security
  • Contact Us

Client Libraries & SDKs

home/Documentation/Client Libraries & SDKs
  • Device SDK Reference
    • Overview
    • Device Authentication Options
    • Data Flow
    • Public Methods
      • Device Connection
      • Send Telemetry
      • Get Attributes
      • Send acknowledgment
      • Update Twin
    • SDKs (Message version 1.0)
      • DOT NET (C#)
      • Node.js
      • Java
      • Python
      • iOS
      • Android
      • Embedded
      • C language
      • Build Your Own SDK
      • Node-RED
        • IoTConnect Node-red 1.0.9
        • IoTConnect Node-red 1.0.8
      • Node-RED Subflow
        • Single Device
        • Multiple Device
    • SDKs (Message version 2.1)
      • Python
      • DOT NET (C#)
      • C language
        • IoTConnect Generic C SDK
          • Linux Build Instructions
          • Windows Build Instructions
      • Python 1.1
    • Code Samples
      • Node.js
        • TPM 3.1
        • Standard SDK 3.0
        • Standard
        • TPM
        • Standard SDK 3.0.1
        • Standard 2.0
      • Java
        • Standard
        • Standard 2.0
        • Standard 3.0
      • Python
        • Standard 2.0
        • TPM 2.1
        • Standard 3.0.1
        • Standard
        • TPM
          • TPM 3.0.1
        • TPM 3.0
        • Standard 3.0.2
        • Standard 3.0.3
        • Standard 3.0.4
        • Python SDK
      • iOS
        • ios1.0.1
      • C Language
        • nRF9160 DK
        • STM32L4
        • ESP32
        • Standard 3.0
        • Standard 2.0
        • Standard 3.1
      • Android
        • Standard 3.0
        • Standard 2.0.6
        • Standard 2.0.0
      • DOT NET (C#)
        • Standard
        • Standard 2.0
        • Standard 3.0
    • Device Message 1.0
      • D2C (Device to Cloud)
        • IoTConnect SDK
        • Custom SDK
      • C2D (Cloud to Device)
        • IoTConnect SDK
        • Custom SDK
      • Troubleshooting & Response codes
      • Know Your Essentials
    • Device Message 2.1
    • AWS Device Message 2.1
    • SDK Deep-diving
Download PDF

Standard 2.0.6

Card Image

Android SDK

Version 2.0.6

Updated On 03/21

Sample Code for lettest version of SDK

# Date Name Download
1 03/19/2021 Standard authorized firmware sample v2.0.6 Download

How to run an Android sample code?

Prerequisite tools:

  1. Java 8 (or above)
  2. Android SDK
  3. Android Studio

Installation:

1. You can direclty import the sdk package from gradle URL.

2. Please verify jcenter in your root build.gradle at the end of repositories.

allprojects {
	repositories {
		...
			jcenter()
	}
}

2. Add the dependency package.

dependencies {
	implementation 'com.iotconnectsdk:iotconnectpoc:2.0.6'			
}

Usage:

To initialize the SDK object need to import above dependency package.

Prerequisite input data

  • Get your Environment(ENV) Details
  • Get your CPID
uniqueId = <<uniqueId>>; 
cpId = <<CPID>>; 
env = <<env>>;

– To Initialize the SDK object and get the device information to connect to the device with IoTConnect cloud.

IoTConnectSDK ioTConnectSDK = new IoTConnectSDK(Activity.this, cpId, uniqueId, IotSDKCallback, environment);

Implement methods to receive the command from Cloud to Device(C2D)

IotSDKCallback 	// To receive the command from Cloud to Device(C2D).

//Command receive from Cloud to Device(C2D).
@Override
public void onReceiveMsg(String message) {
	if (!message.isEmpty()) {
		JSONObject mainObject = new JSONObject(message);
		String cmdType = mainObject.getString("cmdType");
		JSONObject dataObj = mainObject.getJSONObject("data");
		
		switch (cmdType) {
			case "0x01":
				// Device Command
			break;

			case "0x02":
				// Firmware OTA Command
			break;
		}
	}
}

Get attributes List

@Override
public void attributeData(List attributesBeanList) {
	Log.d(TAG,data);
}

Get connection status

@Override
public void onConnectionStateChange(boolean isConnected) {
	if (isConnected) {
		//device connected 
	} else {
		//device not connected
	}
}	

To send the data from Device To Cloud(D2C)

data = [{
	"uniqueId": "<< Device UniqueId >>",
	"time" : "<< date >>", //Date format should be as defined
	"data": {} // example : {"temperature": 15.55, "gyroscope" : { 'x' : -1.2 }}
}];
iotConnectSDK.sendData(data);

To send the command acknowledgment

JSONObject obj = new JSONObject("{
	"ackId": "",
	"st": "",
	"msg": "",
	"childId": ""
}");
String messageType = "";
ioTConnectSDK.sendAck(JSONObject obj, String messageType)
  • ackId(*) : Command Acknowledgment GUID which will receive from command payload (data.ackId)
  • st(*) : Acknowledgment status sent to cloud
    4 = Fail
    6 = Device command[0x01]
    7 = Firmware OTA command[0x02])
  • msg : It is used to send your custom message
  • childId : Leave it blank(“”)
  • msgType : Message type
    5 = Device command[0x01]
    11 = Firmware OTA command[0x02]

Disconnect iotConnect on Activity onDestroy

@Override
protected void onDestroy() {
	super.onDestroy();
	if (ioTConnectSDK != null) {
		ioTConnectSDK.disconnectSDK();
	}
}

Powered by Softweb – An Avnet Company.

Copyright ©2022 Avnet, Inc. All rights reserved.

Human Rights Privacy Terms of Use