UserAccountManager.getInstance()。logIntoDJIUserAccount导致致命异常

时间:2019-05-13 23:43:11

标签: android dji-sdk

此问题也发布在这里:

https://github.com/dji-sdk/Mobile-SDK-Android/issues/410#thread-subscription-status

https://github.com/DJI-Mobile-SDK-Tutorials/Android-VideoStreamDecodingSample/issues/30

有关

此问题发生在修改后的UX示例中。

应用程序调试日志显示以下错误,该错误似乎在UserAccountManager.getInstance().logIntoDJIUserAccount时发生 已执行-省略此方法后,应用运行良好-但是没有视频流。

错误消息:

**E/AndroidRuntime: FATAL EXCEPTION: dji_sdk_callback_thread
    Process: com.dji.uxsdkdemo, PID: 26848
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
        at android.content.ContextWrapper.getTheme(ContextWrapper.java:125)
        at android.app.Dialog.<init>(Dialog.java:193)
        at android.app.Dialog.<init>(Dialog.java:163)
        at dji.internal.useraccount.a.a.<init>(Unknown Source:11)
        at dji.internal.useraccount.a.a(Unknown Source:2)
        at dji.internal.useraccount.a.a(Unknown Source:19)
        at dji.sdk.useraccount.UserAccountManager.logIntoDJIUserAccount(Unknown Source:46)
        at dji.sdk.useraccount.UserAccountManager.logIntoDJIUserAccount(Unknown Source:1)
        at com.dji.uxsdkdemo.DemoApplication.loginAccount(DemoApplication.java:139)
        at com.dji.uxsdkdemo.DemoApplication.access$000(DemoApplication.java:22)
        at com.dji.uxsdkdemo.DemoApplication$1.onRegister(DemoApplication.java:75)
        at dji.internal.b.a$11.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:198)
        at android.os.HandlerThread.run(HandlerThread.java:65)**

我们正在使用4.9版的SDK

(
    compile ('com.dji:dji-uxsdk:4.9')
    provided ('com.dji:dji-sdk-provided:4.9')
)

Windows 10和M600PRO无人机。

IDE是Android Studio,API级别为27。移动设备是具有Android 8.1的Oppo R17。

以下文件“ Demoapplication.java”供您参考:

package com.dji.uxsdkdemo;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;

import dji.common.error.DJIError;
import dji.common.error.DJISDKError;
import dji.common.useraccount.UserAccountState;
import dji.common.util.CommonCallbacks;
import dji.sdk.base.BaseComponent;
import dji.sdk.base.BaseProduct; 
import dji.sdk.sdkmanager.DJISDKManager;
import dji.sdk.useraccount.UserAccountManager;

public class DemoApplication extends Application {

    public static final String FLAG_CONNECTION_CHANGE = "uxsdk_demo_connection_change";

    private static BaseProduct mProduct;
    private Handler mHandler;
    private DJISDKManager.SDKManagerCallback mDJISDKManagerCallback;

    private Application instance;
    public void setContext(Application application) {
        instance = application;
    }

    @Override
    public Context getApplicationContext() {
        return instance;
    }

    public DemoApplication() {

    }

    /**
     * This function is used to get the instance of DJIBaseProduct.
     * If no product is connected, it returns null.
     */
    public static synchronized BaseProduct getProductInstance() {
        if (null == mProduct) {
            mProduct = DJISDKManager.getInstance().getProduct();
        }
        return mProduct;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mHandler = new Handler(Looper.getMainLooper());


        /**
         * When starting SDK services, an instance of interface DJISDKManager.DJISDKManagerCallback will be used to listen to
         * the SDK Registration result and the product changing.
         */

        mDJISDKManagerCallback = new DJISDKManager.SDKManagerCallback() {

            @Override
            public void onRegister(DJIError error) {
                //isRegistrationInProgress.set(false);
                if (error == DJISDKError.REGISTRATION_SUCCESS) {
                    DJISDKManager.getInstance().startConnectionToProduct();

                    Toast.makeText(getApplicationContext(), "SDK registration succeeded!", Toast.LENGTH_LONG).show();
                    loginAccount();
                } else {

                    Toast.makeText(getApplicationContext(),
                            "SDK registration failed, check network and retry!",
                            Toast.LENGTH_LONG).show();
                }
            }
            @Override
            public void onProductDisconnect() {
                Toast.makeText(getApplicationContext(),
                        "product disconnect!",
                        Toast.LENGTH_LONG).show();
            }
            @Override
            public void onProductConnect(BaseProduct product) {
                Toast.makeText(getApplicationContext(),
                        "product connect!",
                        Toast.LENGTH_LONG).show();
            }

            @Override
            public void onComponentChange(BaseProduct.ComponentKey key,
                                          BaseComponent oldComponent,
                                          BaseComponent newComponent) {
//            Toast.makeText(getApplicationContext(),
//                           key.toString() + " changed",
//                           Toast.LENGTH_LONG).show();

            }
        };



        //Check the permissions before registering the application for android system 6.0 above.
        int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
        int permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.READ_PHONE_STATE);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (permissionCheck == 0 && permissionCheck2 == 0)) {

            //This is used to start SDK services and initiate SDK.
            DJISDKManager.getInstance().registerApp(getApplicationContext(), mDJISDKManagerCallback);
        } else {
            Toast.makeText(getApplicationContext(), "Please check if the permission is granted.", Toast.LENGTH_LONG).show();
        }

    }

    private void loginAccount(){

        UserAccountManager.getInstance().logIntoDJIUserAccount(this,
                new CommonCallbacks.CompletionCallbackWith<UserAccountState>() {
                    @Override
                    public void onSuccess(final UserAccountState userAccountState) {
                        Log.e("TAG", "Login Success");
                    }
                    @Override
                    public void onFailure(DJIError error) {
                        Log.e("TAG", "Login Error:" + error.getDescription());
                    }
                });
    }

    private void notifyStatusChange() {
        mHandler.removeCallbacks(updateRunnable);
        mHandler.postDelayed(updateRunnable, 500);
    }

    private Runnable updateRunnable = new Runnable() {

        @Override
        public void run() {
            Intent intent = new Intent(FLAG_CONNECTION_CHANGE);
            getApplicationContext().sendBroadcast(intent);
        }
    };

}

0 个答案:

没有答案