Skip to main content

Autoupload Priority

Consider a scenario where two apps using the Photos SDK are installed on the same device. If they work under the same account, then both of them can upload photos / videos to the cloud, since these applications will not "know" about each other. This will lead to duplicate content on the backend.

The Photos SDK offers the following solution. The PhotoManager component can be initialized in two modes:

Regardless of the mode selected, the package-id of the second application should be passed to the PhotoManager after initialization.

For example, let's say that the "Cloud Storage" application initializes the SDK in the Standalone mode, since this application has all the features of the cloud storage and the application "My Account" (from a telecom operator) uses the Integration mode. In this case, the "Cloud Storage" app will perform an autoupload, while the "My Account" app will stop uploading.

note

If you do not intend to use two applications working simultaneously on one device with the same cloud storage using the same account, then it is preferable to set:

  • competitionMode = STANDALONE
  • competitorPackageName = <some package that does not ever exist>
important

Do NOT set packageId of your current app as competitorPackageName parameter of '' PhotoManager.initInstance () '' method. This may lead to unpredictable results.

Standalone#

In Standalone mode, the Photos SDK works as follows:

  1. Checks if the second application is installed. If not, then goes to step 4.
  2. Sends the broadcast "com.cloudike.cloudikephotos.Competition.StopUpload" to the second application.
  3. Registers a broadcast receiver that waits for a response from the second application: "com.cloudike.cloudikephotos.Competition.CompetitorStoppedUpload".
  4. Launches autoload.

Checking for a second application on the device is performed using the PackageManager:

internal fun isPackageInstalled(        packageName: String,        packageManager: PackageManager): Boolean {    return try {        packageManager.getPackageInfo(packageName, 0)        true    } catch (e: PackageManager.NameNotFoundException) {        false    }}

Integration#

In the Integration Photos mode, the SDK acts as follows:

  1. Checks if the second application is installed. If not, then starts autoload.
  2. Registers a broadcast receiver that:
    1. Waiting for the system event "android.intent.action.PACKAGE_REMOVED" for the second application.
    2. Starts autoload.
  3. Registers a broadcast receiver that:
    1. Waiting for a message from the second application "com.cloudike.cloudikephotos.Competition.StopUpload".
    2. Stops startup.
    3. Sends confirmation to the second application "com.cloudike.cloudikephotos.Competition.CompetitorStoppedUpload".