SDK Integration

Last Updated on : 2024-04-02 02:18:10download

This topic describes how to integrate with MiniApp SDK into your Android project. This helps you build a Smart Life miniapp and run it on your IoT app.

Preparation

Finish the following operations on the Tuya IoT Development Platform before you integrate MiniApp SDK into your project:

  • Register a developer account, create a product, define data points (DPs), and continue with subsequent steps.
  • Create an app based on Smart Life App SDK and get the key information that is required to activate the SDK. For more information, see Preparation.

Prerequisites

The Smart Life App SDK is integrated into your project. For more information, see Fast Integration with Smart Life App SDK for Android.

Import SDK

To import the SDK, configure your repository declaration. Perform the following steps:

  1. Add the Maven repository URLs of the MiniApp SDK to the build.gradle file in the parent project.

    repositories {
        maven { url 'https://maven-other.tuya.com/repository/maven-releases/' }
        maven { url "https://maven-other.tuya.com/repository/maven-commercial-releases/" }
    }
    
  2. Add the following dependencies to the file build.gradle:

    android {
        packagingOptions {
            pickFirst 'lib/*/libv8wrapper.so'
            pickFirst 'lib/*/libv8android.so'
        }
    }
    
    dependencies {
        //Version management component - required
        implementation enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:5.8.16")
        // BizBundle of the MiniApp SDK - required
        implementation "com.thingclips.smart:thingsmart-bizbundle-miniapp"
        // The collection of components that enable extension capabilities for your miniapp. You can add the respective dependency as needed.
        // The basic extension capabilities similar to those supported by most APIs of WeChat Mini Program.
        implementation "com.thingclips.smart:thingsmart-bizbundle-basekit"
        // The code scanning capability.
        // To implement code scanning for users registered inside mainland China, add the following dependencies:
        // implementation 'com.thingclips.smart:thingsmart-qrcode-scankit:5.8.0-rc.1'
        // implementation 'com.thingclips.smart:thingsmart-qrcode-api:5.8.0-rc.3'
    
        // To implement code scanning for users registered outside mainland China, add the following dependencies:
        // implementation 'com.thingclips.smart:thingsmart-qrcode-mlkit:5.8.0-rc.2'
        // implementation 'com.thingclips.smart:thingsmart-qrcode-api:5.8.0-rc.3'
    }
    
  3. After the code scanning component is imported, go to assets > module_app.json in your project, and finish the following configurations:

    The configurations for users inside mainland China cannot coexist with those for users outside mainland China. Apply either of these two types of configurations.

    1. Add the following code block to the moduleMapp:

      // For users inside mainland China
      "com.thingclips.smart.scankit.qrcode.ScanKitModuleApp": [
      "scan_qrcode"
      ]
      
      // For users outside mainland China
      // "com.thingclips.smart.mlkit.qrcode.MLKitModuleApp": [
      //   "scan_qrcode"
      // ]
      
    2. Add the following code block to the serviceMap:

      // For users inside mainland China
      "com.thingclips.smart.multimedia.qrcode.api.ScanQRCodeService": "com.thingclips.smart.scankit.qrcode.ScanQRCodeServiceImpl"
      
      // For users outside mainland China
      // "com.thingclips.smart.multimedia.qrcode.api.ScanQRCodeService": "com.thingclips.smart.mlkit.qrcode.ScanQRCodeServiceImpl"
      

Add description of permissions

To integrate all SDK-based capabilities, the following typical system permissions are required: storage, camera, recording, reading phone status, location, Bluetooth, and contacts. To invoke the respective APIs and components, you must get the respective permission.

Permission name Permission value Respective API
Read from album READ_EXTERNAL_STORAGE
  • chooseImage
  • chooseMedia
Write to album WRITE_EXTERNAL_STORAGE saveToAlbum
Camera CAMERA
  • scanCode
  • chooseImage
  • chooseMedia
Bluetooth BLUETOOTH
  • API for pairing a device
  • API for device control
Microphone RECORD_AUDIO chooseMedia

Open miniapp

/**
 * Opens a miniapp by miniapp ID.
 */
fun openMiniAppByAppId(context: Context, appId : String, appVersion: String? = null, params: Bundle? = null)

/**
 * Opens a miniapp by URL.
 */
fun openMiniAppByUrl(context: Context, url : String, params: Bundle? = null)

/**
 * Opens a miniapp by QR code scanning.
 */
fun openMiniAppByQrcode(context: Context, url : String, params: Bundle? = null)

For more information about how to make other API requests, see Quick Start.

Import capability package

To expand the possibilities of your miniapp, Tuya encapsulates commonly used capabilities into different capability packages. You can integrate the desired capability package into your project to access the included API resources and thus easily implement the respective business functionality.

Basic capability package

This package provides most API resources similar to those supported by WeChat Mini Program, for example, upload, download, recording, interaction, and file operations. We recommend that you integrate the basic capability package by default.

// The basic extension capabilities similar to those supported by most APIs of WeChat Mini Program.
implementation "com.thingclips.smart:thingsmart-bizbundle-basekit"
// The code scanning capability.
// To implement code scanning for users registered inside mainland China, add the following dependencies:
// implementation 'com.thingclips.smart:thingsmart-qrcode-scankit:5.8.0-rc.1'
// To implement code scanning for users registered outside mainland China, add the following dependencies:
// implementation 'com.thingclips.smart:thingsmart-qrcode-mlkit:5.8.0-rc.2'

Business capability package

This package provides typical APIs enabled by Tuya. For example, query multilingual settings and open control panels. We recommend that you integrate the business capability package by default.

implementation "com.thingclips.smart:thingsmart-bizbundle-bizkit"

Home management capability package

This package provides the capability to query information about homes. These capabilities are essential to Tuya-enabled business. Each home is the largest unit to manage smart scenes.

implementation "com.thingclips.smart:thingsmart-bizbundle-homekit"

To integrate the home management capability package, in addition to the preceding capability dependency, integrate the Home Management UI BizBundle provided by the Smart Life App SDK into your project.

Device control capability package

This package encapsulates device control capabilities that help implement device control, device removal, and device status listening. For more information, see Device Control UI BizBundle of the Smart Life App SDK.

Map capability package

This package encapsulates map capabilities that help implement typical features, such as location and geofencing.

implementation "com.thingclips.smart:thingsmart-bizbundle-mapkit"
// To integrate AutoNavi into your project, you must also add the following component:
//    implementation 'com.thingclips.smart:thingsmart-amap:5.8.1'
//    implementation 'com.thingclips.smart:thingsmart-amaplocation:5.3.0-rc.2'
// To integrate Google Map into your project, you must also add the following component:
//    implementation 'com.thingclips.smart:thingsmart-googlemap:5.0.1'
//    implementation 'com.thingclips.smart:thingsmart-googlelocation:4.5.0-rc.1'

Media capability package

This package encapsulates video and camera capabilities. To use the media components video and camera, integrate the media capability package into your project.

implementation "com.thingclips.smart:thingsmart-bizbundle-mediakit"

Pairing capability package

This package encapsulates the pairing process and provides the API resources to implement pairing. To customize a pairing process, integrate the pairing capability package into your project.

implementation "com.thingclips.smart:thingsmart-bizbundle-playNetkit"

P2P transmission capability package

This package encapsulates P2P connection establishment, transmission, and other capabilities, including P2P initialization, connection, upload, download, and destruction features. It applies to robot vacuums, door locks, IPC, and many more.

implementation 'com.thingclips.smart:thingsmart-bizbundle-p2pkit'

IPC business capability package

This package encapsulates IPC business capabilities, including IPC YUV player, doorbell calling, cloud storage signature, and other capabilities. It applies to the development of IPCs, door locks, and robot vacuums.

implementation 'com.thingclips.smart:thingsmart-bizbundle-ipckit'