Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery Voltage #1287

Open
Vickyxdev opened this issue Apr 9, 2024 · 3 comments
Open

Battery Voltage #1287

Vickyxdev opened this issue Apr 9, 2024 · 3 comments

Comments

@Vickyxdev
Copy link

How to get Battery Voltage in DJI SDK 4.16?

@danilofariadutra
Copy link

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++;
        }

@Vickyxdev
Copy link
Author

thanks for information

@dji-lyt
Copy link

dji-lyt commented Apr 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants