Skip to main content

Autoupload

Start Autoupload#

The Photos SDK starts auto-upload automatically when all necessary conditions are met and stops when some of them are not met. If some of the conditions are not met initially, auto-upload never starts until all of them are fixed. The list of reasons, which are currently preventing auto-upload from starting can be retrieved from UploadStatus, see Monitor Autoupload Status

Basically, to start auto-upload, the following actions should be taken:

Autoupload Settings#

The autoupload configuration has the following fields and default values:

// Auto upload on/offisAutoUploadEnabled = false
// Cellular data upload allowedisCellularUploadEnabled = false
// Minimum battery charge for auto uploadminBatteryLevel = 0.0f
// Video upload allowedisVideoUploadEnabled = false
// Roaming upload allowedisRoamingUploadEnabled = false
// The maximum number of attempts to upload a photo/video file to the cloud.// If 0, then the number of attempts is not limited. If 1 - only one attempt is given, etc.maxRetryCount = 3
// Controls how many uploaders dedicated to upload both photos and videos. The greater value,// the more uploaders upload media including videos. Default - 0.5.// For example: `videoUploadPriority == 0.3f` means that 30% of upload workers will process both// videos and photos. While 70% of uploaders will upload photos only. These photo-dedicated// uploaders will begin upload videos when there are no more photos left in the queue.// However, if new photos are added they switch back to photo uploading.videoUploadPriority = 0.5f

To change a configuration, call the following method:

PhotoManager.uploader.configuration =    PhotoManager.uploader.configuration.copy(            minBatteryLevel = 0.3f        )

Links - UploaderConfiguration.

Monitor Autoupload Status#

The autoupload status allows you to monitor the autoupload process, as well as receive information regarding the interruptios in work. To get the status, call the following method:

//..photosScope.launch {    PhotoManager.uploader.stateFlow.collect { status ->        // handle status    }}//..

The PhotoManager.uploader.stateFlow is a kotlin StateFlow, which emits a new status object every time a change during autoupload occurs. The status object has the following properties:

data class UploadStatus(
    /**     * Auto uploader status.     */    val autoUploaderStatus: UploaderStatus,
    /**     * Forced uploader status.     */    val forcedUploaderStatus: UploaderStatus,
    /**     * Family uploader status.     */    val familyUploaderStatus: UploaderStatus,
    /**     * List of all upload factors.     */    val factors: Set<UploadFactor>
) {    data class UploaderStatus(        /**         * List of factors why upload is inactive. The uploader is inactive if the set is empty.         */        val inactiveFactors: Set<UploadFactor>,
        /**         * The number of media files that are currently uploading.         */        val activeMediaCount: Int,
        /**         * The number of photos that are in the queue for uploading.         */        val inQueuePhotoCount: Int,
        /**         * The number of videos that are in the queue for uploading.         */        val inQueueVideoCount: Int    )
    enum class UploadFactor {
        /** Uploader-specific factor. Uploader is disabled */        UPLOADER_DISABLED,
        /** Uploader-specific factor. The uploader did not find any items to upload. */        UPLOADER_NO_ITEMS_FOUND,
        /** For the uploader to work, scanning the backend storage is required. */        BACKEND_STORAGE_NOT_READ,
        /** User does not have enough space in the cloud storage */        BACKEND_STORAGE_LOW_VOLUME,
        /** For the uploader to work, scanning the family backend storage is required. */        FAMILY_BACKEND_STORAGE_NOT_READ,
        /** User does not have enough space in the cloud storage */        FAMILY_BACKEND_STORAGE_LOW_VOLUME,
        /** For the uploader to work, scanning the family is required. */        FAMILY_NOT_READ,
        /** For the uploader to work, scanning the local storage is required. */        LOCAL_STORAGE_NOT_READ,
        /** Permissions to work with local storage have not been granted. */        LOCAL_STORAGE_PERMISSIONS_NOT_GRANTED,
        /** Apps negotiating about which one will be responsible for uploading photos to the cloud */        APP_COMPETITION_NOT_FINISHED,
        /** Another app is responsible for uploading to the cloud. This app will not upload. */        APP_ANOTHER_INSTALLED,
        /** No internet connection */        NETWORK_NO_CONNECTION,
        /** No Wi-Fi connection, but the use of mobile network is prohibited */        NETWORK_NO_WIFI_CONNECTION,
        /** Current connection in roaming, but use of mobile network in roaming is prohibited */        NETWORK_ROAMING,
        /** Auth token has been expired. App need to re-login user. */        NETWORK_TOKEN_EXPIRED,
        /** Certificate pinning failure. No network requests can be proceeded. */        NETWORK_CERTIFICATE_PINNING_FAILED,
        /** Not enough battery level to continue auto-upload */        BATTERY_LOW_CHARGE_LEVEL,
        /** SDK is being logged out */        LOGGING_OUT    }}

After the backend gallery and the local gallery are read, if there is no other reason for delay, autoupload starts automatically. For more details, see Autoupload Settings

Ongoing Notification#

In order for the system not to kill the application while uploading the photos to the cloud (especially when the application is not active and works in the background), the Photo SDK launches the WorkManager's worker and displays an ongoing notification. The application is responsible for preparing the UI of this notification, since only this application has all the necessary resources.

The interaction is as follows:

  • The Photos SDK declares interface UploadNotificationAdapter
  • The application implements this interface and sets the implementation to the SDK using PhotoManager.uploader.setNotificationAdapter(adapter) .
  • The SDK calls the application's implementation every time when upload status is changed.
  • Application returns a new notification object on each call.

The interface has the following specifications:

interface UploadNotificationAdapter {    fun statusToNotification(uploadStatus: UploadStatus): Notification}

The method statusToNotification receives the upload status and returns a ready notification displayed by WorkManager's worker from the Photos SDK. The statusToNotification ()method is called each time the upload status is changed.

Also, the application must independently register a message channel on Android 8+.