Skip to main content

Download Cleaner

The Cleaner SDK includes a component that allows you to work with the downloads folder. This component provides a function for analyzing the amount of memory occupied by a folder, as well as a function for clearing the contents of this folder.

Analysis of the downloads folder#

Analysis of the downloads folder is an operation that allows you to obtain information about the contents of the folder before starting to clean it up. This operation is not required to clear the downloads folder. However, to inform the user about the content, it is recommended to use it.

The following code example demonstrates how to use the analysis operation to retrieve data about the contents of the downloads folder:

viewModelScope.launch {        CleanerManager.downloads.analyze().flowOn(Dispatchers.IO).collect { cleanerState ->            val state: CleanerState = cleanerState        }}

This function returns a flow during which the operation state is thrown in the form of an object [CleanerState](# cleaner-state). Within this function, this object takes the following values:

  • [CleanerState.Analyzing](# cs-analyzing) - this value means the beginning of the analysis process;
  • [CleanerState.AnalysisResult](# cs-analysing-result) - this value signals the completion of the analysis process and has a size field that contains information about the size of the download folder in bytes.

Links - CleanerState.

Clearing the download folder#

Use the following code example to clean up the downloads directory:

viewModelScope.launch {        CleanerManager.downloads.clear().flowOn(Dispatchers.IO).collect { cleanerState ->            val state: CleanerState = cleanerState        }}

This function returns a flow during which the operation state is thrown in the form of an object [CleanerState](# cleaner-state). Within this function, this object takes the following values:

  • [CleanerState.Cleaning](# cs-cleaning) - this value means that the process of deleting files is active and has a progress field that contains the progress of deleting files;
  • [CleanerState.CleaningResult](# cs-cleaning-result) - this value signals the completion of the cleaning process and has a size field that contains information about the deleted size in bytes.

Links - CleanerState.