English
English
简体中文
Contact Us
Register
Log In

IoT App SDK

Native Control Panel for Switch

Last Updated on : 2021-08-13 00:23:18download

Native control panels for switches are developed based on native code and support all switch categories.

Advantages

  • Lightweight and free of frameworks such as React Native.
  • Support all switch categories and apply to new products without app launching.
  • Facilitate debugging during development.

    Native Control Panel for SwitchNative Control Panel for SwitchNative Control Panel for Switch

How it works

Dependency

implementation 'com.tuya.smart:TuyaSwitchPanelPanel:1.0.1'

API description

void openDefaultPanel(Context context, String devId, MenuBean menuBean);

Parameters

Parameter Description
context The context to start an activity.
devId The device ID.
menuBean Creates and displays custom menus and events.

menuBean can be set to null if it is not required.

MenuBean data model

Field Data type Description
menuRes int The ID of a custom menu resource.
menuItemId int The value of itemId for the custom menu.
bundle Bundle The Bundle that passes custom data. You can use IDefaultPanelController.BUNDLE_KEY to get the value from Intent.
activityClassName String The value of ClassName for a custom activity. Example: TestActivity.class.getName().

Java example

MenuBean menuBean = new MenuBean();
menuBean.setMenuRes(R.menu.common_menu);
menuBean.setMenuItemId(R.id.check);
Bundle bundle = new Bundle();
bundle.putString("DEV_ID_KEY", devId);
menuBean.setBundle(bundle);
menuBean.setActivityClassName(TestActivity.class.getName());
IDefaultPanelController defaultPanelController = PluginManager.service(IDefaultPanelController.class);
defaultPanelController.usePanel(new HomeSDKPanel());
defaultPanelController.openDefaultPanel(context, devId, menuBean);
  • Native control panels use startActivityForResult(Intent, IDefaultPanelController.REQUEST_CODE_DEFAULT_PANEL) to start a custom activity.
  • Under onActivityResult, the application disables native control panels if (requestCode == IDefaultPanelController.REQUEST_CODE_DEFAULT_PANEL && resultCode == RESULT_OK) is true.