[!] 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 installed.
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.video", "com.dji.protocol" and "com.dji.common" to the key.
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".
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.
Note: The Swift compiler error looks like this: Inclue of non-modular header inside framework module 'DJISDK'.
Register Application
Import the DJI SDK header file into ViewController.m.
Give the view controller the DJISDKManagerDelegate protocol to follow.
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."; }else { NSLog(@"registerAppSuccess"); }
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)
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 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.
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.
// When the compile and target version is higher than 22, please request the following permission at runtime to ensure the SDK works well. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { checkAndRequestPermissions(); }
setContentView(R.layout.activity_main);
//Initialize DJI SDK Manager mHandler = new Handler(Looper.getMainLooper());
}
/** * Checks if there is any missing permissions, and * requests runtime permission if needed. */ privatevoidcheckAndRequestPermissions(){ // Check for permissions for (String eachPermission : REQUIRED_PERMISSION_LIST) { if (ContextCompat.checkSelfPermission(this, eachPermission) != PackageManager.PERMISSION_GRANTED) { missingPermission.add(eachPermission); } } // Request for missing permissions if (missingPermission.isEmpty()) { startSDKRegistration(); } elseif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { showToast("Need to grant the permissions!"); ActivityCompat.requestPermissions(this, missingPermission.toArray(new String[missingPermission.size()]), REQUEST_PERMISSION_CODE); }
}
/** * Result of runtime permission request */ @Override publicvoidonRequestPermissionsResult(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) { missingPermission.remove(permissions[i]); } } } // If there is enough permission, we will start the registration if (missingPermission.isEmpty()) { startSDKRegistration(); } 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:
privatevoidstartSDKRegistration(){ if (isRegistrationInProgress.compareAndSet(false, true)) { AsyncTask.execute(new Runnable() { @Override publicvoidrun(){ showToast("registering, pls wait..."); DJISDKManager.getInstance().registerApp(MainActivity.this.getApplicationContext(), new DJISDKManager.SDKManagerCallback() { @Override publicvoidonRegister(DJIError djiError){ if (djiError == DJISDKError.REGISTRATION_SUCCESS) { showToast("Register Success"); DJISDKManager.getInstance().startConnectionToProduct(); } else { showToast("Register sdk fails, please check the bundle id and network connection!"); } Log.v(TAG, djiError.getDescription()); }
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:
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.