The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

SDK for Java Project Configuration

Last updated: 2026-05-09 16:04:41

IoT Hub device SDK for Java relies on a secure and powerful data channel to enable IoT developers to quickly connect devices to the cloud for two-way communication. You only need to complete the corresponding project configuration to connect devices.

Prerequisites

The product and device have been created according to the Device Access Preparation.

Reference Method

If you need to conduct project development through jar reference, you can add dependencies in build.gradle under the module directory as follows:
dependencies {
...
implementation 'com.tencent.iot.hub:hub-device-java:x.x.x'
}
Note:
You can set the above x.x.x to the latest version according to Version Explanation .
If you need to develop a project through code integration, you can download the SDK for Java source code from GitHub.

Connection Authentication

Device identity authentication supports two methods: key authentication and certificate authentication:
If using key authentication, you need ProductID, DevName, and DevPSK.
If using certificate authentication, you need ProductID, CertFile, and PrivateKeyFile.
Below is the sample code for connection authentication:
private String mProductID = "YOUR_PRODUCT_ID";
private String mDevName = "YOUR_DEVICE_NAME";
private String mDevPSK = "YOUR_DEV_PSK";
private String mCertFilePath = null;
private String mPrivKeyFilePath = null;
TXMqttConnection mqttconnection = new TXMqttConnection(mProductID, mDevName, mDevPSK, new callBack());
mqttconnection.connect(options, null);
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mqttconnection.disConnect(null);