Skip to main content

Photo Cleaner

Cleaner SDK includes compotent that works with PhotoSDK to find and remove duplicate media files stored in the cloud.

important

Before you start working with this module, connect and initialize the photo library in the main module of your project as described in this [manual](# getting-started), and also make sure that the Internet is available during the operation.

Analysis of duplicate media files#

Analysis of duplicate media files is an operation that allows you to get information about all duplicate media files on the device, copies of which are stored in the cloud, before starting to delete them. This operation is not required to remove duplicates. However, to inform the user about the content, it is recommended to use it.

The following code example demonstrates how to use a parse operation to retrieve data about duplicate media files:

viewModelScope.launch {        CleanerManager.photos.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.

Cleaning up duplicate media files#

Use the following code example to remove duplicate media files:

viewModelScope.launch {        CleanerManager.photos.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.