Auto Update Apps

Auto Update functionality encompasses the following major activities:

  • Check if device user has opted in for Auto Updates, and, if not already opted in, surface a UI to opt in to Auto Updates.
  • Send Opt-in for Auto Updates and optional MMP tracking URL.
  • Listen to broadcast for auto update job scheduling and app installation results.

Check for Auto Update Opt-In

The getIsAutoUpdateEnabled method allows you to determine if a user has already opted in for Auto Updates. It is the responsibility of the Host App to surface a UI based on the results of the getIsAutoUpdateEnabled method. For the getIsAutoUpdateEnabled method, DT returns the following values:

true
User has opted in for Auto Updates.
false
User has declined Auto Updates.
null
Opt in has never been set.

For false and null scenarios, surface an opt-in UI based on the scenario to encourage the user to sign up for auto updates.

Type

Asynchronous

Description

Returns whether the user is opted in for Auto Updates.

Send Opt-In and MMP URL for Auto Update

To automatically update apps, the device user must first opt in for this function. The Host App must collect the opt-in selection and send the opt-in to DT using the setAutoUpdateEnabled method. Additionally, if you want to specify a specific MMP tracking URL (clientMMPUrl) for updates, send the URL when initializing connection with the SDK.

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initializeSdk(clientSecret, clientMMPUrl) //clientSecret and MMPUrl are stored somewhere in your app.
        igniteService.connect(this)
 
        // Call remote function on button click
        findViewById(R.id.userOptInCheckBox).setOnCheckedChangeListener {
            IgniteServiceSdk.setAutoUpdateEnabled(isChecked)
        }
}

Type

Asynchronous

Description

Passes user opt-in for Auto Update to DT.

Parameters

enabled
true if user is opted in and false otherwise. No default value.

Broadcasts for App Updates

The SDK stores all App Update opt-in data and schedules update jobs for those opted-in.  

Broadcast - App Update Job Scheduling

Listen to the jobStatusBroadcastReceiver to track scheduled jobs.

override fun onStart() {
        super.onStart()

        val intentFilter = IntentFilter().apply {
            addAction(IgniteServiceSdk.ACTION_APP_UPDATE_JOB_SCHEDULED)
            addAction(IgniteServiceSdk.ACTION_APP_UPDATE_JOB_CANCELLED)
        }

        registerReceiver(jobStatusBroadcastReceiver, intentFilter)
    }
    
    override fun onStop() {
        super.onStop()

        unregisterReceiver(jobStatusBroadcastReceiver)
    }

    private val jobStatusBroadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent) {
            when (intent.action) {
                IgniteServiceSdk.ACTION_APP_UPDATE_JOB_SCHEDULED -> {
                    toast("App Update Job Scheduled.")
                }
                IgniteServiceSdk.ACTION_APP_UPDATE_JOB_CANCELLED -> {
                    toast("App Update Job Cancelled.")
                }
                else -> {
                    println("$TAG Unknown Broadcast Action")
                }
            }
        }
    }

This broadcast receiver may contain the following actions:

ACTION_APP_UPDATE_JOB_SCHEDULED
Sent when App Update is successfully scheduled.
ACTION_APP_UPDATE_JOB_CANCELLED
Sent when App Update is successfully cancelled.

Note

DT does not broadcast when the App Update job fails to schedule. Instead, the next time the host app initializes the SDK, DT will attempt to schedule the update again.

Listen to Broadcast -  App Update Job Completion

Listen to the BroadcastReceiver for installation status of App Update jobs.

registerReceiver(
            object : BroadcastReceiver() {
                override fun onReceive(context: Context?, intent: Intent?) {
                    intent?.let {
                        when (it.action) {
                            IgniteServiceSdk.ACTION_APP_UPDATE_SUCCESS -> Log.d(
                                TAG,
                                "Demo App Updated Successful"
                            )
                            IgniteServiceSdk.ACTION_APP_UPDATE_FAILED -> Log.d(
                                TAG,
                                "Demo App Updated Failed"
                            )
                            else -> Log.d(TAG, "Invalid Action")
                        }
                    }
                }
            },
            IntentFilter().apply {
                addAction(IgniteServiceSdk.ACTION_APP_UPDATE_SUCCESS)
                addAction(IgniteServiceSdk.ACTION_APP_UPDATE_FAILED)
            }
        )

 

This broadcast receiver may contain the following actions:

ACTION_APP_UPDATE_SUCCESS
Sent when app has been successfully updated
ACTION_APP_UPDATE_FAILED
Sent when app failed to update

Back to Top ⇧