Device reset
Some products have a reset button to clear device configurations and restore the device to its factory settings. In some scenarios, the manufacturer needs the cloud to be notified when a device is reset. Call the Link SDK reset API to trigger this notification from your Android app.
On Android devices, reset is always triggered by a user action — for example, a physical reset button press or an in-app button tap. Call the SDK's reset interface to initiate the sequence. The SDK then follows one of two flows depending on whether the device is online:
Online: The SDK calls the reset interface to notify the cloud. If the call succeeds, the SDK destroys the LinkKit instance by calling
deinit. If the call fails, the SDK falls back to the offline flow.Offline: The SDK sets a reset flag and destroys the LinkKit instance. When the instance is re-initialized, it detects the flag, establishes a connection, and calls the reset interface. The SDK sends a device discovery response only after the reset completes. Uninstalling the app or clearing its data removes the flag, preventing reset on the next startup.
LinkKit.getInstance().reset(new IConnectSendListener() {
@Override
public void onResponse(ARequest aRequest, AResponse aResponse) {
ALog.d(TAG, "reset onResponse ");
}
@Override
public void onFailure(ARequest aRequest, AError aError) {
ALog.d(TAG, "reset onFailure");
}
});
User detachment on the Smart Life Open Platform
On the Alibaba Cloud IoT Smart Life Open Platform, a user attaches a device to their mobile app to control it. When the device is sold or transferred, the new owner can press the reset button to detach the device from the original user. This prevents the original user from controlling the device.
Call the LinkKit.getInstance().reset interface to send the detach notification to the cloud.
Re-enabling dynamic registration
With dynamic registration, only the ProductKey and ProductSecret are flashed onto the device at the factory. The device obtains its DeviceSecret from Alibaba Cloud IoT Platform through dynamic registration. Once a DeviceSecret is issued, the platform rejects any further dynamic registration attempts for that device.
Store the DeviceSecret in non-application storage. Do not delete it when the user presses the reset button, uninstalls the app, or clears app data.
If the DeviceSecret is lost, recover the device by:
Recording its ProductKey and DeviceName.
Deleting the device in the Alibaba Cloud Management Console.
Creating a new device with the same DeviceName.
Make sure your production builds prevent users from deleting the DeviceSecret.