Skip to content Skip to sidebar Skip to footer

Difference Between Dji Onproductchange And Onproductconnect

Context I'm building a Flutter Plugin above the DJK SDK. For that, I have to implement the communication with the aircraft on the native side, and I'm doing it with Java. I'm also

Solution 1:

Difference

According to the SDK DocsonProductChanged is primarily used to detect when the connection status changes from only remote controller connected to a full connection between the aircraft and the SDK running on your device.

Keep in mind that when the aircraft is disconnected, this method will be called with an instance of an aircraft, but this instance will come with property isConnected as false. If you print the aircraft object to the console you will notice that if isConnected is true, it will print the aircraft name, otherwise, it will print "None".

As long for the onProductConnect, it will be called always after DJISDKManager.getInstance().registerApp() succeeded or after you manually connect to the aircraft with success using DJISDKManager.getInstance().startConnectionToProduct(). In my tests, even though the app registration succeeds, the method will return false, so you might need to check if the SDKManagerCallback::onRegister results in DJISDKError.REGISTRATION_SUCCESS.

Solution

You need to listen to component change events. Unfortunately just because the product is connected it does not mean that the individual components, such as the flight controller, camera etc are connected. You will need to implement onComponentChange and add a listener to detect when a component is connected. These don't always connect in the same order and may start to connect before or after the product is connected.

@OverridepublicvoidonComponentChange(
  BaseProduct.ComponentKey componentKey,
  BaseComponent oldBaseComponent,
  BaseComponent newBaseComponent
) {
  newBaseComponent.setComponentListener(isConnected -> {
    // check if component connected and access dataif (isConnected) {
      if(componentKey == ComponentKey.FLIGHT_CONTROLLER) {
        // DJISDKManager.getInstance().getProduct() should no longer be null
        DJISDKManager.getInstance().getProduct().getModel();
      }
    }
  })
}

Post a Comment for "Difference Between Dji Onproductchange And Onproductconnect"