Open Vickyxdev opened 7 months ago
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++;
}
thanks for information
Thank you for @danilofariadutra response. The method you provided is indeed the correct way to obtain battery information in MSDK V4.
How to get Battery Voltage in DJI SDK 4.16?