Run Sample Code

2024-12-31
No Rating

This guide assumes you are using Android Studio Koala 2024.1.1 and newest MSDK version. You can read the Readme fileopen in new window of MSDK Sample project in advanced to get familiar with the project.

Register as a DJI Developer

Register for a DJI Developer accountopen in new window.

Note: During the registration process, email information, credit card information and phone number will need to be supplied to verify the registration. Any credit card information given will only be used for verification and will not be charged.

Generate an App Key

Every application needs a unique App Key to initialize the SDK. To create an App Key for an application, please go to Developer Centeropen in new window of the DJI developer website.

  1. Select the "Apps" tab on the left.
  2. Select the "CREATE APP" button on the right.
  3. Enter the App Type, App Name, Software Platform, Packeage Name, and the other informations by yourself. The Packeage Name should be the same as applicationId of the sample project. You can refer to the build.gradle fileopen in new window and the following code segment.
    defaultConfig {
        applicationId "com.dji.sampleV5.aircraft"
        minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
        manifestPlaceholders["API_KEY"] = project.AIRCRAFT_API_KEY

        ndk {
            abiFilters 'arm64-v8a'
        }
    }
  1. An application activation email will be sent to complete App Key generation. Developer can go back to the developer center after the successful activation, then the App Key is generated for further configuration.

Android Sample App

The SDK doesn't need to be downloaded to run the Android sample application as it's already included in the project.

Android Sample Code Setting

  1. Download or clone the MSDK Android sample projectopen in new window.
  2. Select the File > Open... at the tool bar of Android studio, and import the android-sdk-v5-as project.
  3. Our sample project has packaged the setting. After the import, developer can fill the generated "App Key" string into "gradle.properties" fileopen in new window. You can refer to the following code segment.
#msdk api key
AIRCRAFT_API_KEY = Please add your app key here.

Run the Sample App

  1. Compile and install the sample code. Because the remote controllers(RC) equipped with the aircraft are different, the installation is difference. For RC with screen, App is installed at the RC. For RC that needs to be connected to mobile device, App is installed at the mobile device. The supported aircraft models and equipped RC can be read from the Supported Product List and Firmware Versionopen in new window of Release Note.

Notes:

  • For M300 RTK and DJI smart controller enterprise, App can be installed both at the RC and mobile device.
  • The highest supported Android version of MSDK is 14 and the API level is 34.

Before the usage, permissions are in need. The following are the range of permissions. The meaning of these permissions can refer to Manifest.permissionopen in new window. The location authority, media file authority, and recording authority will be shown by system, you can choose whether to allow.

  • Permissions for SDK

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    
  • Permissions for sample modules
    app for all, app for handheld, app for aircraft. The permissions for this three modules are the same.

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    
  • permissions for uxsdk

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
  1. If the words "Registration Status: Registered" appear in the upper left corner of the main interface of the Sample, the sample code is running successfully. If the "Product Name: real product name" appears, the MSDK is successfully connected to the aircraft. The following figure shows the flow chart of the SDK Manager API call.

If "{errorType='SDK', errorCode='INVALID_METADATA', innerCode='null', description='The metadata received from server is invalid, please reconnect to the server and try.', hint='The metadata received from server is invalid, please reconnect to the server and try.'}" appears, the error might be that your Package Name for the App key application is different with the "applicationId" parameter of sample code.

Note:

When starting a third-party App based on MSDK on the remote controller(DJI RC Pro) that matching camera drones, official app DJI Fly should be forcibly exited from the application and notification interface under the DJI RC Pro remote controller system settings interface to ensure a normal start of the third-party app.

ISDKManageropen in new window is used for SDK management. It is used to initialize and register to SDK, connect to product, get product information.

If you have any comments or confusion about our documentation, you can click here to give feedback and we will get back to you as soon as possible.