(1)新建一个Android Application Project.如果你想的话,你可以为the Application, Project, and Package起名字。在项目设置下的'Create Activity'页面上,创新一个的活动并把名字改成'FPVActivity'。布局活动应该自动填写到'activity_fpv'
(2)将软件包解压缩。导入一个叫Lib文件夹(Eclipse\DJI-SDK-Android-V2.1.0)到Eclipse里面(File -> Import -> Android -> Existing Android Code into Workspace)。下一步,把导入的文件加到你的library (right click on your project -> Select "Properties" -> Select "Android" -> Add).
(3)已被导入的library应该被存在这里:
Android Studio
(1) 创新一个新的Android Studio Project.可给这个apllication一个新名字。点击'next'直到你点到'Customize the Activity'页面。你应该把你的activity的名字变成'FPVActivity'。布局的名字会自动的变成'activity_fpv'。点击'Finish'。
(2)将下载的SDK软件包按如此步骤Go to File -> New -> Import Module导入Android Studio。在'Source Directory'里,找一个文件叫DJI-SDK-LIB(Android Studio\DJI-SDK-Android-V2.1.0\Lib\DJI-SDK-LIB)。点击Finish.
DJIDrone.connectToDrone(); // Connect to the drone
(3) 现在我们可以实例化一个视频数据的回调接口DJIReceivedVideoDataCallBack(), 然后调用API public public void setReceivedVideoDataCallBack(DJIReceivedVideoDataCallBack mReceivedVideoDataCallBack)来获取实时视频数据(raw H264格式)。用户可以实现自己的代码去处理该视频数据。这里,我们使用DJI SDK提供的解码器来解码该视频数据,并把解码出来的视频显示在SurfaceView。
// function for taking photo
private void captureAction(){
CameraMode cameraMode = CameraMode.Camera_Capture_Mode;
// Set the cameraMode as Camera_Capture_Mode. All the available modes can be seen in
// DJICameraSettingsTypeDef.java
DJIDrone.getDjiCamera().setCameraMode(cameraMode, new DJIExecuteResultCallback(){
@Override
public void onResult(DJIError mErr)
{
String result = "errorCode =" + mErr.errorCode + "\n"+"errorDescription =" + DJIError.getErrorDescriptionByErrcode(mErr.errorCode);
if (mErr.errorCode == DJIError.RESULT_OK) {
CameraCaptureMode photoMode = CameraCaptureMode.Camera_Single_Capture;
// Set the camera capture mode as Camera_Single_Capture. All the available modes
// can be seen in DJICameraSettingsTypeDef.java
DJIDrone.getDjiCamera().startTakePhoto(photoMode, new DJIExecuteResultCallback(){
@Override
public void onResult(DJIError mErr)
{
String result = "errorCode =" + mErr.errorCode + "\n"+"errorDescription =" + DJIError.getErrorDescriptionByErrcode(mErr.errorCode);
handler.sendMessage(handler.obtainMessage(SHOWTOAST, result)); // display the returned message in the callback
}
}); // Execute the startTakePhoto API if successfully setting the camera mode as
// Camera_Capture_Mode
} else {
handler.sendMessage(handler.obtainMessage(SHOWTOAST, result));
// Show the error when setting fails
}
}
});
}
// function for starting recording
private void recordAction(){
// Set the cameraMode as Camera_Record_Mode.
CameraMode cameraMode = CameraMode.Camera_Record_Mode;
DJIDrone.getDjiCamera().setCameraMode(cameraMode, new DJIExecuteResultCallback(){
@Override
public void onResult(DJIError mErr)
{
String result = "errorCode =" + mErr.errorCode + "\n"+"errorDescription =" + DJIError.getErrorDescriptionByErrcode(mErr.errorCode);
if (mErr.errorCode == DJIError.RESULT_OK) {
//Call the startRecord API
DJIDrone.getDjiCamera().startRecord(new DJIExecuteResultCallback(){
@Override
public void onResult(DJIError mErr)
{
String result = "errorCode =" + mErr.errorCode + "\n"+"errorDescription =" + DJIError.getErrorDescriptionByErrcode(mErr.errorCode);
handler.sendMessage(handler.obtainMessage(SHOWTOAST, result)); // display the returned message in the callback
}
}); // Execute the startTakePhoto API
} else {
handler.sendMessage(handler.obtainMessage(SHOWTOAST, result));
}
}
});
}
// function for stopping recording
private void stopRecord(){
// Call the API
DJIDrone.getDjiCamera().stopRecord(new DJIExecuteResultCallback(){
@Override
public void onResult(DJIError mErr)
{
String result = "errorCode =" + mErr.errorCode + "\n"+"errorDescription =" + DJIError.getErrorDescriptionByErrcode(mErr.errorCode);
handler.sendMessage(handler.obtainMessage(SHOWTOAST, result));
// Show the return of the API calling
}
});
}
你已经完成了整篇教程的学习: 你已经学会了如何配置DJI Mobile SDK的Android开发环境,并成功用它开发app来展示飞行器相机的FPV画面。同时,你也学会如何使用DJI Mobile SDK来开发app,展示飞行器相机的FPV视图,控制DJI 飞行器的相机进行拍照和录像操作,这两项功能经常被使用到,也是一款航拍app的基本功能点。但是,要开发一款很酷的航拍app,你还有很长的一段路要走。像预览SD卡中的照片和视频,展示飞机的OSD数据等等。请继续关注我们后续的教程,希望你喜欢!