Mobile-SDK-Android icon indicating copy to clipboard operation
Mobile-SDK-Android copied to clipboard

Battery Voltage

Open Vickyxdev opened this issue 10 months ago • 3 comments

How to get Battery Voltage in DJI SDK 4.16?

Vickyxdev avatar Apr 09 '24 06:04 Vickyxdev

If your aircraft has just one battery:

try {
            DJISampleApplication.getProductInstance().getBattery().setStateCallback(new BatteryState.Callback() {
                @Override
                public void onUpdate(BatteryState batteryState) {
                    batteryState.getVoltage();
                }
            });
        } catch (Exception exception) {
            ToastUtils.showToast(String.format("Error in getting battery voltage %s", exception.getMessage()));
        }

If your aircraft has more than one battery:

      int batteryPos = 0;
        for (Battery battery : DJISampleApplication.getProductInstance().getBatteries()) {
            int finalBatteryPos = batteryPos;
            try {
                battery.setStateCallback(djiBatteryState -> {
                    showToast(String.format("Battery %d: %d", finalBatteryPos, djiBatteryState.getVoltage()));
                });
            } catch (Exception exception) {
                ToastUtils.showToast(String.format("Error in getting battery voltage %s", exception.getMessage()));
            }
            batteryPos++;
        }

danilofariadutra avatar Apr 09 '24 11:04 danilofariadutra

thanks for information

Vickyxdev avatar Apr 09 '24 17:04 Vickyxdev

Thank you for @danilofariadutra response. The method you provided is indeed the correct way to obtain battery information in MSDK V4.

dji-lyt avatar Apr 10 '24 08:04 dji-lyt