Skip to main content

Realization of photo album function

1. Overview

This tutorial will take Android SDK Demo as an example to describe how to use album APIs in an application. By the end of this tutorial, you will learn how to obtain media data (photos and videos) from an aircraft, and download or delete media data from the album. As files in the album are photos and videos, the media files mentioned in this tutorial all refer to photos and videos.

2. Preparations

2.1 Android studio

Use Android Studio for project development. Currently, the SDK does not support Eclipse.

2.2 Integrate the SDK

Follow the instructions described in the Integrating the AUTEL Mobile SDK document to integrate the AUTEL SDK. Then listen for connections with the aircraft, return the BaseProduct object, and use this object to call the corresponding module. This tutorial only describes the album module.

3. Obtain Files from the Album

After you integrate the SDK, use the listener methods provided by the SDK to listen for APIs connected with the aircraft and obtain the album module information through these APIs.

3.1 Add Listeners

Add listeners to MainAcitivity of your application (or to the place where you need) to listen for connections to the aircraft, return the BaseProduct object, and then obtain API information through BaseProduct.

  Autel.setProductConnectListener(new ProductConnectListener() {
@Override
public void productConnected(BaseProduct product) {
//.....
/**
* The obtained product is the API for obtaining aircraft information
*/
AutelAlbum album = product.getAlbum();
//....

}

3.2. Obtain Album Information

After you obtain AutelAlbum, call corresponding API methods to obtain relevant album data, for example:

//Obtain files from the album
product.getAlbum().getMedia(0, 10,
new CallbackWithOneParam<List<MediaInfo>>() {
@Override
public void onFailure(AutelError autelError) {
//Operation failed
}

@Override
public void onSuccess(List<MediaInfo> mediaInfos) {
//Operation succeeded
}
});

MediaInfo describes the detailed information of a single media file (For details, see the last section in the document)

4. Camera APIs

4.1 Obtain Files from the Album

Query the album in the SD card. You can specify the position where the query starts and the position where the query ends. In the end, you can use the listener API to return a collection of lists (MediaInfo). The following code example shows the specific API that is used:

 /**
* Obtain files from the album
* @param var1 album type->ALL(0),VIDEO(1),PHOTO(2);
* @param var2 position where the query starts
* @param var3 position where the query ends
* @param var4 listener API for returning the value
*/
void getMedia(AlbumType var1, int var2, int var3,
CallbackWithOneParam<List<MediaInfo>> var4);

/**
* Obtains files from the album. Reload method. The default album query type is ALL(0)
*
* @param var1 position where the query starts
* @param var2 position where the query ends
* @param var3 listener API for returning the value
*/
void getMedia(int var1, int var2,CallbackWithOneParam<List<MediaInfo>>
var3);
  1. Query the album in the flash memory. The following code example shows the specific API that is used:
/**
* Obtain the album information from the flash memory of the aircraft
* @param var1 file type->ALL(0),VIDEO(1),PHOTO(2);
* @param var2 position where the query starts
* @param var3 position where the query ends
* @param var4 result callback API
*/
void getFMCMedia(AlbumType var1, int var2, int var3,
CallbackWithOneParam<List<MediaInfo>> var4);

/**
* Obtain the album information from the flash memory of the aircraft
* @param var1 position where the query starts
* @param var2 position where the query ends
* @param var3 result callback API
*/
void getFMCMedia(int var1, int var2,
CallbackWithOneParam<List<MediaInfo>> var3);

4.2. Download Data from the Album

You can use the downloadPicture method of the AutelAlbum API to download photos from your aircraft album to a specified path. The following code example shows the specific API method that is used:

  /***
* Download the media files from your aircraft to a local path
* @param var1 album path where photos are stored in the aircraft, which can be obtained by using the getOriginalMedia() method of MediaInfo.

* @param var2 path for storing downloaded media files
*/
void downloadPicture(String var1, String var2);

4.3. Download Thumbnail Pictures of Media Files

Obtain the specific thumbnail pictures of media files from the album. The following code example shows the specific API method that is used:

     if (null == okHttpManager) {
okHttpManager = new OkHttpManager.Builder().build();
}

okHttpManager.download(mediaInfo.getLargeThumbnail(), "file storage path",
new ResponseCallBack<File>() {
@Override
public void onSuccess(File file) {
/**
* Downloading succeeded
*/
}
@Override
public void onFailure(Throwable throwable) {
/**
* Downloading failed
*/
}
});

4.4. Obtain the Resolution and FPS

You can obtain the resolution and FPS of a media file stored in the SD card based on the media information (MediaInfo) of that file. In addition, you can use the same way to obtain the resolution and FPS of a local media file. The following code example shows the specific APIs that are used:

 /**
* Obtains the video resolution from a specified object
* @param var1 object from which the video resolution is obtained
* @param var2 obtains the callback result VideoResolutionAndFps resolution information
*/
void getVideoResolutionFromHttpHeader(MediaInfo var1,
CallbackWithOneParam<VideoResolutionAndFps> var2);

/**
* Returns the video resolution and FPS of local files
* @param var1 local media file
* @return resolution and FPS
*/
VideoResolutionAndFps getVideoResolutionFromLocalFile(File var1);

You can obtain the resolution and FPS of a media file stored in the flash memory based on the media information (MediaInfo) of that file. The APIs used are similar to those for obtaining the media information of a file stored in the SD card. The following code shows the specific API that is used:

  /**
*Obtains the video resolution from a specified object (flash memory)
* @param var1 object from which the resolution is obtained
* @param var2 obtains the callback result
*/
void getFMCVideoResolutionFromHttpHeader(MediaInfo var1,
CallbackWithOneParam<VideoResolutionAndFps> var2);

4.5. Deletes the Media Data

You can delete a single media file or multiple files in batches from the SD card. The deleted data can be returned by using the callback API CallbackWithOneParam. The following code example shows the API that is used:

 /**
* Deletes media data (batch delete)
* @param var1 list of media files to be deleted. You can delete a maximum of 50 files at a time
* @param var2 callback implemented when deleting media data from the camera
*/
void deleteMedia(List<MediaInfo> var1,
CallbackWithOneParam<List<MediaInfo>> var2);

/**
* Deleted media data (a specified media file)
* @param var1 deleted media data
* @param var2 callback implemented when deleting media data from the camera
*/
void deleteMedia(MediaInfo var1,
CallbackWithOneParam<List<MediaInfo>> var2);

The API used for deleting media data from the flash memory is similar to the API used for deleting media data from the SD card. The following code example shows the specific API that is used:

 /**
* Deletes media data from the flash memory (batch delete)
* @param var1 a collection of media data to be deleted
* @param var2 callback for the deletion operation
*/

void deleteFMCMedia(List<MediaInfo> var1,
CallbackWithOneParam<List<MediaInfo>> var2);

/**
* Deletes media data from the flash memory (a single file)
* @param var1 data to be deleted
* @param var2 callback for the deletion operation
*/
void deleteFMCMedia(MediaInfo var1,
CallbackWithOneParam<List<MediaInfo>> var2);

5. Callback APIs

Most of camera APIs use callback to return results to developers. The CallbackWithOneParam API is inherited from the FailedCallback API. The abstract methods in the two APIs are described below:

FailedCallback API:

  public interface FailedCallback {
/**
* Callback for operation failure
* @param var1 error message (error code and error message)
*/
void onFailure(AutelError var1);
}

CallbackWithOneParam API:

public interface CallbackWithOneParam<T> extends FailedCallback {
/**
* Callback for a successful request
* @param var1 query returned data
*/
void onSuccess(T var1);
}

6. API Description

6.1 MediaInfo API

API methodsDescription
getFileSize()Obtains the size of a media file
getFileTimeString()Obtains the creation time of a file
getSmallThumbnail()Obtains a small thumbnail picture of a media file
getLargeThumbnail()Obtains a large thumbnail picture of a media file
getOriginalMedia()Obtains the URL of a media file
getVideoResolutionAndFps()Obtains the video resolution and FPS
getVideoEncodeFormat()Obtains the media encoding format (only for videos)
getVideoPlayUrl()Obtains the URL for playing a media file (only for videos)

6.2 VideoResolutionAndFps Parameter Description

ParameterDescription
VideoResolutionVideo resolution enumeration class
VideoFpsVideo FPS enumeration class
VideoEncodeFormatVideo encoding format enumeration class