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.
Screenshots in this section are generated using Xcode 7.3.
$(PODS_ROOT)/Headers/Publicin Build Settings to help fix the Swift compiler error.
Note: The Swift compiler error looks like this: Inclue of non-modular header inside framework module 'DJISDK'.
DJISDKManagerDelegateprotocol to follow.
DJISDKAppKeykey in the info.plist file of the Xcode project and paste the generated App Key string into its string value:
viewDidAppearas shown below:
DJISDKManagerDelegateprotocol requires the
appRegisteredWithErrormethod to be implemented.
showAlertViewWithTitleto give the registration result in a simple view.
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:
Screenshots in this section are generated using Android Studio 3.0.
A new application can be used to show how to integrate the DJI SDK into an Android Studio project.
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"
The main changes should be:
packagingOptionsto prevent any unexpected crash of the application.
provideddependencies to import the latest DJI Android SDK Maven dependency.
Double Check Maven Dependency
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 MApplication.java file and replace the content with the following:
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 MainActivity.java in the app module.
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.
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:
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
onComponentChange() methods of the
Finally methods for
showToast need to be implemented:
The application must be granted permissions to in order for the DJI SDK to operate.
Double click on AndroidManifest.xml in the app module.
package=com.dji.ImportSDKDemo and before
android:name=".MApplication"at the beginning of the
activityelement as shown below to prevent the activity restarts when the screen orientation changes and also set the activity's screen orientation as portrait mode:
Generate an App Key, and replace "Please enter your App Key here." with the App Key string.
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:
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.