1. Integrate SDK

1.1.1. Create Project

Build your project in the Android Studio.

1.1.2. Configure the build.gradle

Add the following codes to the build.gradle file.

defaultConfig {
    ndk {
        abiFilters "armeabi-v7a"
    }
   }
    dependencies {
        implementation 'com.alibaba:fastjson:1.1.67.android'
        implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.3'
        // Tuya Home's current latest release version:
        implementation 'com.tuya.smart:tuyasmart:3.17.6'
    }

repositories {
    mavenLocal()
    jcenter()
    google()
}

[!TIP]

  • The Tuya Smart sdk solely supports the platform of armeabi-v7a architecture by default. Developer may refer to the GitHub if you need other platforms.
  • After version 3.11.0, the so libraries of armeabi-v7a, arm64-v8a, armeabi platforms have been integrated into sdk. Please remove the relevant so-banks of sdk manually placed in the local, and use the default provided by sdk.

1.1.3. Integrated security image

Click the download button to download the security image.

Rename the downloaded security image to "t_s.bmp" and move it to the assets/ folder in the project directory.

1.1.4. Set the AndroidManifest.xml

Set appkey and appSecret in the AndroidManifest.xml file, and configure corresponding permissions, etc.

<meta-data
    android:name="TUYA_SMART_APPKEY"
    android:value="Appkey" />
<meta-data
    android:name="TUYA_SMART_SECRET"
    android:value="AppSecret" />

1.1.5. Proguard Configuration

please add this proguard configuration to proguard-rules.pro files.

#fastJson
-keep class com.alibaba.fastjson.**{*;}
-dontwarn com.alibaba.fastjson.**

#mqtt
-keep class com.tuya.smart.mqttclient.mqttv3.** { *; }
-dontwarn com.tuya.smart.mqttclient.mqttv3.**

#OkHttp3
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

-keep class okio.** { *; }
-dontwarn okio.**

-keep class com.tuya.**{*;}
-dontwarn com.tuya.**

1.2. Use the SDK function in codes

The TuyaHomeSdk is the outbound interface of the Smart Home, and the operations include network configuration, initiation, control, room, group and ZigBee.

1.2.1. Initiate SDK in the Application

Description

It is used to initiate components of communication services, etc.

Example

public class TuyaSmartApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        TuyaHomeSdk.init(this);
    }
}

Note:

The appId and appSecret need to be configured in the AndroidManifest.xml file or the build environment or the codes.

TuyaHomeSdk.init(Application application, String appkey, String appSerect)

1.2.2. Logout of the Tuya Smart Cloud connection

The following interface needs to be invoked to log out of the App.

TuyaHomeSdk.onDestroy();

1.2.3. Monitor the invalidity of registered session

Description

Because of abnormality or long-time absence of operation for 45 or more days, the session will become invalid, and user has to log out of the App and log in again to obtain the session.

Declaration

// Monitor the invalidity of session.
TuyaHomeSdk.setOnNeedLoginListener(INeedLoginListener needLoginListener);

needLoginListener.onNeedLogin(Context context);

Example

public class TuyaSmartApp extends Application {

        @Override
        public void onCreate() {
            super.onCreate();
            // Register in the App.
                TuyaHomeSdk.setOnNeedLoginListener(new INeedLoginListener(){
               @Override
                public void onNeedLogin(Context context) {

                }
    });

[info] Note

  • In case of this kind of callback, please go to the login page and require the user to log in again.

1.2.4. Debug mode

In the debug mode, you can enable the sdk log switch to view more log information and help you locate the problem quickly. It is recommended to turn off the log switch in release mode.

TuyaHomeSdk.setDebugMode(true);

results matching ""

    No results matching ""