sxx7-8 16:20
KeyManager 一开始也是null。要判断,我在每一次通知产品连接的时候都会重置一遍监听设置。 我现在在getFlightController()为null的时候,一直循环注册,调试也发现它一直在循环,但是返回永远都是null。SDK是4.15,飞机固件已经升级到最新。代码如下,请帮忙看看是否少了什么步骤,谢谢!
private void startSDKRegistration() {
if (isRegistrationInProgress.compareAndSet(false, true)) {
}
AsyncTask.execute(new Runnable() {
@Override
public void run() {
ToastUtils.setResultToToast("Registering, pls wait...");
DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), new DJISDKManager.SDKManagerCallback() {
@Override
public void onRegister(DJIError djiError) {
if (djiError == DJISDKError.REGISTRATION_SUCCESS) {
DJILog.e("App registration", DJISDKError.REGISTRATION_SUCCESS.getDeion());
DJISDKManager.getInstance().startConnectionToProduct();
ToastUtils.setResultToToast("SDK Registered Successfully");
showDBVersion();
KeyManager.getInstance().addListener(ProductKey.create(ProductKey.CONNECTION), new KeyListener() {
@Override
public void onValueChange(@Nullable Object o, @Nullable Object o1) {
Log.d(TAG, String.format("onProductConnect newProduct:%s", o1));
if (DJISDKManager.getInstance().getProduct() != null && DJISDKManager.getInstance().getProduct() instanceof Aircraft && ((Aircraft)DJISDKManager.getInstance().getProduct()).getFlightController() != null) {
fly.init();
}else {
startSDKRegistration();
}
notifyStatusChange();
}
});
} else {
ToastUtils.setResultToToast("SDK Registration Failed. Please check the bundle ID and your network\n" +
" connectivity"+ djiError.getDeion());
}
Log.v(TAG, djiError.getDeion());
hideProcess();
}
@Override
public void onProductDisconnect() {
Log.d(TAG, "onProductDisconnect");
notifyStatusChange();
}
@Override
public void onProductConnect(BaseProduct baseProduct) {
Log.d(TAG, String.format("onProductConnect newProduct:%s", baseProduct));
if (DJISDKManager.getInstance().getProduct() != null && DJISDKManager.getInstance().getProduct() instanceof Aircraft && ((Aircraft)DJISDKManager.getInstance().getProduct()).getFlightController() != null) {
fly.init();
}else {
startSDKRegistration();
}
notifyStatusChange();
}
@Override
public void onProductChanged(BaseProduct baseProduct) {
Log.d(TAG, String.format("onProductChanged newProduct:%s", baseProduct));
notifyStatusChange();
}
@Override
public void onComponentChange(BaseProduct.ComponentKey componentKey,
BaseComponent oldComponent,
BaseComponent newComponent) {
if (newComponent != null) {
newComponent.setComponentListener(mDJIComponentListener);
}
Log.d(TAG,
String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",
componentKey,
oldComponent,
newComponent));
notifyStatusChange();
}
@Override
public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
}
@Override
public void onDatabaseDownloadProgress(long current, long total) {
int process = (int) (100 * current / total);
Log.d(TAG, "DB load process : " + process);
if (process == lastProcess) {
return;
}
lastProcess = process;
showProgress(process);
if (process % 25 == 0){
ToastUtils.setResultToToast("DB load process : " + process);
}else if (process == 0){
ToastUtils.setResultToToast("DB load begin");
}
}
});
}
});
}
|