Last Updated on : 2024-04-01 06:08:48download
Scene UI BizBundle for Android provides the service logic and UI to implement adding and editing smart scenes in the smart scene module.
Smart scenes include the following types: tap-to-run and automation.
Tuya supports users’ smart life requirements. For example, set weather conditions or device status as triggers for a specific smart scene. When any triggers occur, one or more linked devices will run predefined tasks.
Integrate Smart Life App SDK for Android into your project with Android Studio and add the framework of the UI BizBundle to your project.
To use Scene UI BizBundle in your project, add the following configuration in the resource directory res/values/values.xml
of the main project:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_scene_support">true</bool>
</resources>
If you have a strong demand for online real-time synchronization of scene data across multiple terminals, it is recommended that you manually execute the following code once after logging in and before using the scene business (it only needs to be called once during the application life cycle):
SceneHomePipeLine().run()
build.gradle
dependencies {
api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:${biz_bom_version}")
api ("com.thingclips.smart:thingsmart-bizbundle-scene")
api "com.thingclips.smart:thingsmart:${sdk_version}}"
}
The UI BizBundle relies on the implementation of IThingSceneBusinessService
to provide services.
Example
// Returns the services provided by the Scene UI BizBundle.
IThingSceneBusinessService iThingSceneBusinessService = MicroContext.findServiceByInterface(IThingSceneBusinessService.class.getName());
Accesses the page for adding a scene by home ID.
API description
public abstract void addSceneBean(Activity activity, long homeId, int requestCode);
Starting from App SDK v5.0.0, you can call iThingSceneBusinessService.addSceneBean
to add a scene. The type of response parameter of onActivityResult
is NormalScene
.
For App SDK versions earlier than v5.0.0, ITuyaSceneBusinessService.addScene
is used to add a scene. The type of response parameter of onActivityResult
is SmartSceneBean
. However, this method has been deprecated and not recommended. You can go to the legacy API document and check the implementation of this feature.
Parameters
Parameter | Type | Description |
---|---|---|
activity | Activity | The object of Activity . |
homeId | long | The home ID. For more information, see Home Information Management. |
requestCode | int | The request code. The value can be returned by onActivityResult . |
Example
if(null != iThingSceneBusinessService && homeId != 0) {
iThingSceneBusinessService.addSceneBean(activity, homeId, requestCode);
}
Accesses the page for editing a scene by scene data and home ID.
API description
Opens the page for editing a scene.
public abstract void editSceneBean(Activity activity, long homeId, NormalScene sceneBean, int requestCode);
Starting from App SDK v5.0.0, you can call iThingSceneBusinessService.editSceneBean
to edit a scene. The type of response parameter of onActivityResult
is NormalScene
.
For App SDK versions earlier than v5.0.0, iThingSceneBusinessService.editScene
is used to edit a scene. The type of response parameter of onActivityResult
is SmartSceneBean
. However, this method has been deprecated and is not recommended. You can go to the legacy API document and check the implementation of this feature.
Parameters
Parameter | Type | Description |
---|---|---|
activity | Activity | The object of Activity . |
homeId | long | The home ID. For more information, see Home Information Management. |
sceneBean | NormalScene | The object of scene data. You can call smart scene API methods to get the required data. |
requestCode | int | The request code. The value can be returned by onActivityResult . |
Example
ThingHomeSdk.getSceneServiceInstance().baseService().getSimpleSceneAll(homeId,
new IResultCallback<List<NormalScene>>() {
@Override
public void onSuccess(List<NormalScene> normalScenes) {
if (!normalScenes.isEmpty()) {
NormalScene sceneBean = normalScenes.get(0);
if (null != iThingSceneBusinessService) {
iThingSceneBusinessService.editSceneBean(SceneActivity.this, homeId, sceneBean, requestCode);
}
}
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
Sets the geographic location before a user can use the scene conditions and validity period. Otherwise, city information cannot be automatically returned in specific searches. However, users can still select a target city from the city list.
API description
public abstract void setAppLocation(double longitude, double latitude);
Parameters
Parameter | Description |
---|---|
longitude | The longitude, provided by the third-party map service that is integrated into your app. |
latitude | The latitude, provided by the third-party map service that is integrated into your app. |
Example
if(null != iThingSceneBusinessService){
iThingSceneBusinessService.setAppLocation(lng, lat);
}
Provides the geographic location in the scene conditions. It can be ignored if accounts that are registered in locations outside mainland China are not managed. The map class must be set for accounts registered in locations outside mainland China. Otherwise, the cities in mainland China are queried by default.
API description
public abstract void setMapActivity(Class<? extends Activity> clazz);
Parameters
Parameter | Description |
---|---|
clazz | The object of the map Activity class. You can integrate the Maps Service UI BizBundle to set this parameter. |
Example
if(null != iThingSceneBusinessService){
// The following example shows the built-in map package that can be available after the Maps Service UI BizBundle is integrated. You can use a third-party map for implementation as needed.
iThingSceneBusinessService.setMapActivity(com.thingclips.smart.map.generalmap.ui.GeneralMapActivity.class);
}
Sends a specified location on the map to the UI BizBundle after the map class is integrated. This helps to update the location information.
API description
public abstract void saveMapData(double longitude, double latitude, String city, String address);
Parameters
Parameter | Description |
---|---|
longitude | The longitude. |
latitude | The latitude. |
city | The city information. |
address | The address information. |
Example
if(null != iThingSceneBusinessService){
iThingSceneBusinessService.saveMapData(lng, lat, city, address);
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback