Last Updated on : 2024-11-18 11:33:16download
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.
Hilt-related dependencies must be added to your project to use the UI BizBundle. For more information, see Dependency injection with Hilt.
build.gradle
filedependencies {
implementation 'com.tuya.smart:tuyasmart-bizbundle-scene:4.2.0-33'
}
The UI BizBundle relies on the implementation of ITuyaSceneBusinessService
to provide services.
Example
// Returns the services provided by the Scene UI BizBundle.
ITuyaSceneBusinessService iTuyaSceneBusinessService = MicroContext.findServiceByInterface(ITuyaSceneBusinessService.class.getName());
Accesses the page for adding a scene by home ID.
API description
ITuyaSceneBusinessService.addScene(Activity activity, long homeId, int requestCode);;
Parameters
Parameter | Description |
---|---|
activity | The object of Activity . |
homeId | The home ID. For more information, see Home Information Management. |
requestCode | The request code. The value can be returned by onActivityResult . |
Example
if(null != iTuyaSceneBusinessService && homeId != 0) {
iTuyaSceneBusinessService.addScene(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.
ITuyaSceneBusinessService.editScene(Activity activity, long homeId,SceneBean sceneBean, int requestCode);;
Parameters
Parameter | Description |
---|---|
activity | The object of Activity . |
homeId | The home ID. For more information, see Home Information Management. |
sceneBean | The object of scene data. You can call smart scene API methods to get the required data. |
requestCode | The request code. The value can be returned by onActivityResult . |
Example
TuyaHomeSdk.getSceneManagerInstance().getSceneList(homeId, new ITuyaResultCallback<List<SceneBean>>() {
@Override
public void onSuccess(List<SceneBean> result) {
if(!result.isEmpty()){
SceneBean sceneBean = result.get(0);
if(null != iTuyaSceneBusinessService){
iTuyaSceneBusinessService.editScene(SceneActivity.this, homeId, sceneBean, requestCode);
}
}
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
Sets the geographic location before a user can enable 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
ITuyaSceneBusinessService.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 != iTuyaSceneBusinessService){
iTuyaSceneBusinessService.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
ITuyaSceneBusinessService.setMapActivity(Class activity);
Parameters
Parameter | Description |
---|---|
Class | The object of the map Activity class. |
Example
if(null != iTuyaSceneBusinessService){
//TODO: the map Activity implemented in your project.
iTuyaSceneBusinessService.setMapActivity(MapActivity.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
ITuyaSceneBusinessService.saveMapData(double longitude, double latitude,String city, String address);
Parameters
Parameter | Description |
---|---|
longitude | The target longitude. |
latitude | The target latitude. |
city | The city information. |
address | The address information. |
Example
if(null != iTuyaSceneBusinessService){
iTuyaSceneBusinessService.saveMapData(lng, lat, city, address);
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback