Integrate SDK into Application


The examples below import the DJI SDK into a new iOS and Android project. The same steps can be used for integration into an existing application.

Xcode Project Integration

Screenshots in this section are generated using Xcode 7.3.

Create a New Application

  • Open Xcode.
  • Select File->New->Project.
  • Choose Single View Application template.
  • Press Next. createProject
  • "ImportSDKDemo" will be used as the Product Name.
  • Other settings can remain as default. enterProjectInfo

Install SDK with CocoaPods in the Project

  • In Finder, navigate to the root folder of the project, and create a Podfile. To learn more about Cocoapods, please check this guide.
  • Replace the content of the Podfile with the followings:
# platform :ios, '9.0'

target 'ImportSDKDemo' do
pod 'DJI-SDK-iOS', '~> 4.12’
  • Run the following command in the root folder path:
pod install
  • If you install the SDK successfully, you should get the messages similar to the following:
Analyzing dependencies
Downloading dependencies
Installing DJI-SDK-iOS (4.12)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `ImportSDKDemo.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod
  • The DJI SDK framework should now be downloaded and placed in the Pods/DJI-SDK-iOS/iOS_Mobile_SDK/DJISDK.framework path.

Configure Build Settings

  • Open the ImportSDKDemo.xcworkspace file in Xcode.
  • For DJI products that connect to the mobile device through USB, add the "Supported external accessory protocols" key to the info.plist file, and add the strings "", "com.dji.protocol" and "com.dji.common" to the key. supportedExternalAccessoryProtocols
  • Since iOS 9, App Transport Security has blocked cleartext HTTP (http://) resource loading. The "App Transport Security Settings" key must be added and "Allow Arbitrary Loads" must be set to "YES". allowArbitraryLoads
  • For Xcode project which uses Swift 3 above, please delete all the paths in Header Search Paths except $(PODS_ROOT)/Headers/Public in Build Settings to help fix the Swift compiler error. headerSearchPathIssue

Note: The Swift compiler error looks like this: Inclue of non-modular header inside framework module 'DJISDK'. headerSearchPathIssue2

Register Application

  • Import the DJI SDK header file into ViewController.m.
  • Give the view controller the DJISDKManagerDelegate protocol to follow.
#import "ViewController.h"
#import <DJISDK/DJISDK.h>

@interface ViewController ()<DJISDKManagerDelegate>
  • Create a new method registerApp.
  • Use the application's Bundle Identifier to generate an App Key.
  • Create a DJISDKAppKey key in the info.plist file of the Xcode project and paste the generated App Key string into its string value:


  • Invoke registerApp in viewDidAppear as shown below:
- (void)viewDidAppear:(BOOL)animated
[super viewDidAppear:animated];
[self registerApp];

- (void)registerApp
[DJISDKManager registerAppWithDelegate:self];
  • The DJISDKManagerDelegate protocol requires theappRegisteredWithError method to be implemented.
  • Additionally implement showAlertViewWithTitle to give the registration result in a simple view.
- (void)appRegisteredWithError:(NSError *)error
NSString* message = @"Register App Successed!";
if (error) {
message = @"Register App Failed! Please enter your App Key in the plist file and check the network.";

[self showAlertViewWithTitle:@"Register App" withMessage:message];

- (void)showAlertViewWithTitle:(NSString *)title withMessage:(NSString *)message
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];

Run Import SDK Demo

The ImportSDKDemo project can now be run. You can download the sample code of this project from Github: Objective-C | Swift.

As this application is only checking for registration and not interacting directly with a product, no product needs to be connected to the application for this to run. Therefore, the application can either be run on a mobile device (with or without a DJI product connected) or in the iOS simulator. The application will need internet connectivity to perform registration successfully.

If the App Key was generated correctly and the iOS simulator or mobile device has internet connectivity, then the following should be seen:


Android Studio Project Integration

Screenshots in this section are generated using Android Studio 3.0.

Create a New Application

A new application can be used to show how to integrate the DJI SDK into an Android Studio project.

  • Open Android Studio and at the initial screen select Start a new Android Studio project
  • In the New Project screen:
    • Set the Application name to "ImportSDKDemo".
    • Set the Company Domain and Package name to "com.dji.ImportSDKDemo".

Note: Package name is the identifying string required to generate an App Key. The activity java, manifest xml and Gradle script code below assumes Package name is "com.dji.ImportSDKDemo"

  • In the Target Android Devices screen:
    • Select Phone and Tablet form factor.
    • Choose API 19: Android 4.4 (KitKat).
  • In the Add an Activity to Mobile screen choose Empty Activity.
  • In the Configure Activity screen:
    • Set Activity Name: to "MainActivity".
    • Ensure Generate Layout File is checked.
    • Set Layout Name: to "activity_main".
    • Click Finish when done.

Configure Gradle Script

  • In Gradle Scripts double click on build.gradle (Module: app)


  • Update the content with the following:
apply plugin: ''

android {

defaultConfig {


doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
doNotStrip "*/*/"
exclude 'META-INF/'

dependencies {
compile ('com.dji:dji-sdk:4.12')
provided ('com.dji:dji-sdk-provided:4.12')
  • The main changes should be:

    • Add the packagingOptions to prevent any unexpected crash of the application.
    • Add the compile and provided dependencies to import the latest DJI Android SDK Maven dependency.


    • Select Tools -> Android -> Sync Project with Gradle Files and wait for Gradle project sync to finish.
  • Double Check Maven Dependency

    • Select File->Project Structure in the Android Studio menu to open the "Project Structure" window. Then select the "app" module and click the Dependencies tab. You should see the latest DJI SDK compile and provided denpendencies are already imported.

Implement App Registration and SDK Callbacks

Right click on the com.dji.importSDKDemo, and select New->Java Class to create a new java class and name it as "MApplication".


Open the file and replace the content with the following:

package com.dji.importSDKDemo;

import android.content.Context;

import com.secneo.sdk.Helper;

public class MApplication extends Application {

protected void attachBaseContext(Context paramContext) {


Here we override the attachBaseContext() method to add the Helper.install(MApplication.this); line of code.

Note: Since some of SDK classes now need to be loaded before using, the loading process is done by Helper.install(). Developer needs to invoke this method before using any SDK functionality. Failing to do so will result in unexpected crashes.


Double click on in the app module. AndroidImplementationMainActivity

The MainActivity class needs to register the application to get authorization to use the DJI Mobile SDK. It also needs to implement callback methods expected by the SDK.

The MainActivity class will first be modified to include several class variables including mProduct which is the object that represents the DJI product connected to the mobile device.

Additionally the onCreate method will be modified to invoke the checkAndRequestPermissions method to check and request runtime permissions. Also, the checkAndRequestPermissions method will help to invoke the startSDKRegistration() method to register the application. Moreover, the override onRequestPermissionsResult method will help to check if the application has enough permission, if so, invoke the startSDKRegistration() method to register the application.

Now, replace the MainActivity class with:

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getName();
public static final String FLAG_CONNECTION_CHANGE = "dji_sdk_connection_change";
private static BaseProduct mProduct;
private Handler mHandler;

private static final String[] REQUIRED_PERMISSION_LIST = new String[]{
private List<String> missingPermission = new ArrayList<>();
private AtomicBoolean isRegistrationInProgress = new AtomicBoolean(false);
private static final int REQUEST_PERMISSION_CODE = 12345;

protected void onCreate(Bundle savedInstanceState) {

// When the compile and target version is higher than 22, please request the following permission at runtime to ensure the SDK works well.


//Initialize DJI SDK Manager
mHandler = new Handler(Looper.getMainLooper());


* Checks if there is any missing permissions, and
* requests runtime permission if needed.
private void checkAndRequestPermissions() {
// Check for permissions
for (String eachPermission : REQUIRED_PERMISSION_LIST) {
if (ContextCompat.checkSelfPermission(this, eachPermission) != PackageManager.PERMISSION_GRANTED) {
// Request for missing permissions
if (missingPermission.isEmpty()) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
showToast("Need to grant the permissions!");
missingPermission.toArray(new String[missingPermission.size()]),


* Result of runtime permission request
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Check for granted permission and remove from missing list
if (requestCode == REQUEST_PERMISSION_CODE) {
for (int i = grantResults.length - 1; i >= 0; i--) {
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
// If there is enough permission, we will start the registration
if (missingPermission.isEmpty()) {
} else {
showToast("Missing permissions!!!");

The registerApp() method of DJISDKManager has a callback that needs to process two methods for processing the application registration result, and for when the product connected to the mobile device is changed.

Continue to add the startSDKRegistration() method as shown below and implement the onRegister(), onProductDisconnect(), onProductConnect(), onComponentChange(), onInitProcess() and onDatabaseDownloadProgress() methods of the SDKManagerCallback:

private void startSDKRegistration() {
if (isRegistrationInProgress.compareAndSet(false, true)) {
AsyncTask.execute(new Runnable() {
public void run() {
showToast("registering, pls wait...");
DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), new DJISDKManager.SDKManagerCallback() {
public void onRegister(DJIError djiError) {
showToast("Register Success");
} else {
showToast("Register sdk fails, please check the bundle id and network connection!");
Log.v(TAG, djiError.getDescription());

public void onProductDisconnect() {
Log.d(TAG, "onProductDisconnect");
showToast("Product Disconnected");

public void onProductConnect(BaseProduct baseProduct) {
Log.d(TAG, String.format("onProductConnect newProduct:%s", baseProduct));
showToast("Product Connected");

public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent,
BaseComponent newComponent) {

if (newComponent != null) {
newComponent.setComponentListener(new BaseComponent.ComponentListener() {

public void onConnectivityChange(boolean isConnected) {
Log.d(TAG, "onComponentConnectivityChanged: " + isConnected);
String.format("onComponentChange key:%s, oldComponent:%s, newComponent:%s",

public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {


public void onDatabaseDownloadProgress(long l, long l1) {


Finally methods for notifyStatusChange, Runnable and showToast need to be implemented:

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

private Runnable updateRunnable = new Runnable() {

public void run() {
Intent intent = new Intent(FLAG_CONNECTION_CHANGE);

private void showToast(final String toastMsg) {

Handler handler = new Handler(Looper.getMainLooper()); Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), toastMsg, Toast.LENGTH_LONG).show();


The application must be granted permissions to in order for the DJI SDK to operate.

  • Double click on AndroidManifest.xml in the app module. AndroidManifest

  • After package=com.dji.ImportSDKDemo and before <application insert:

<!-- Permissions and features -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-feature android:name="" />
<uses-feature android:name="" />
android:required="false" />
android:required="true" />

<!-- Permissions and features -->
  • Add the android:name=".MApplication" at the beginning of the application element:
android:theme="@style/AppTheme" >
  • Insert the following after android:theme="@style/AppTheme"> and before <activity android:name=".MainActivity">:
<!-- DJI SDK -->
<uses-library android:name="" />
android:value="Please enter your App Key here." />
android:theme="@android:style/Theme.Translucent" >
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
android:resource="@xml/accessory_filter" />
<service android:name="dji.sdk.sdkmanager.DJIGlobalService" >
<!-- DJI SDK -->
  • Insert the android:configChanges="orientation" and android:screenOrientation="portrait" in the activity element as shown below to prevent the activity restarts when the screen orientation changes and also set the activity's screen orientation as portrait mode:
<activity android:name=".MainActivity"
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

Generate an App Key, and replace "Please enter your App Key here." with the App Key string.

Run Import SDK Demo

The ImportSDKDemo project can now be run. You can download the sample code of this project from Github.

As this application is only checking for registration and not interacting directly with a product, no product needs to be connected to the application for this to run. Therefore, the application can either be run on a mobile device (with or without a DJI product connected) or in the Android simulator. The application will need internet connectivity to perform registration successfully.

If the App Key was generated correctly and the Android simulator or mobile device has internet connectivity, then the following should be seen:

FFmpeg License

The DJI Android SDK is dynamically linked with unmodified libraries of FFmpeg licensed under the LGPLv2.1. The source code of these FFmpeg libraries, the compilation instructions, and the LGPL v2.1 license are provided in Github.