- Overview
- How to?
- Adding a download
- Monitoring a download
- Removing a download
- WLanguage functions
Starting with version 27, files can be downloaded in the background, using the system download manager. Therefore, it is no longer necessary to keep the application open to prompt the user to download a file. The download manager allows you to download large files and generate a notification when downloads are complete. Adding a download To propose a download in your Android application: - Define a download request with a variable of type DownloadParameter. This variable contains multiple properties, but only one is really necessary: the Source property which corresponds to the URI of the file to download.
- Add the download in the download manager with DownloadAdd. Once added, the download manager will start the download as soon as possible.
Remark: Download end procedureTo be notified when a download is completed, you can specify a procedure that will be called at the end of the download. To do so, it is necessary to specify the procedure to call in the ProcedureEnd property of the DownloadParameter variable. - If the application was closed before the end of the download, it will be restarted to execute the procedure when the download is completed.
- If the procedure returns True, the download will be deleted as well as the downloaded file. Otherwise, the download will be kept in the download manager and the file will not be deleted.
Monitoring a download To monitor the download in the Android application, retrieve the download details with DownloadAdd, specifying the download identifier provided by DownloadGetInfo. This information is stored in a variable of type DownloadInfo. If there is an error during the download, the download end procedure is started. The Status property of the DownloadInfo variable is set to downloadStatusFailed. In this case, the StatusDetails property can be used to determine the cause of the error. To retrieve all the downloads started by the application in the download manager, use DownloadList. Removing a download To remove a download from the download manager, use DownloadRemove and specify the identifier of the download to be removed. This function will cancel the download and remove it from the download manager, as well as the downloaded file, if it exists. The following WLanguage functions are used to manage downloads:
| | DownloadAdd | Adds a new download in the device's download manager. | DownloadGetInfo | Retrieves the details of a download present in the download manager. | DownloadList | Lists the downloads from the current application in the download manager. | DownloadRemove | Cancels a download by removing it from the download manager, and deletes any existing files. |
Remarks: - Using download functions automatically adds the INTERNET permission to the list of permissions required by the application. The DOWNLOAD_WITHOUT_NOTIFICATION permission is also added if the downloadNotifNone constant is used with the NotificationMode property of the DownloadParameter variable.
- When running the application in the simulator, download functions will have no effect.
Related Examples:
|
Android (WINDEV Mobile): Android Downloads
[ + ] This example illustrates background downloads in WINDEV Mobile and Android. It is no longer necessary to keep the application open to propose the download of a file. The download manager allows you to download large files and to notify the application when the downloads are finished.
|
|
|
|
|