Install by Package Name and Callback

You should be authenticated and a valid token should be present in order to perform installation.

// Initialization

// Install application via package name string and listen to updates using callback
val packageName = "com.package.name"
IgniteServiceSdk.instance().install(packageName, buildSingleInstallationCallback())

// ...

private fun buildSingleInstallationCallback() = object : IResponseCallback<InstallationResponse, Error, InstallationProgress> {
    override fun onScheduled(taskInfo: TaskInfo) {
        Log.i(TAG, "Install application onScheduled(): taskId=${taskInfo.taskId}")
        
        // Store task id when scheduled to track it later if needed
        currentInstallTask = taskInfo.taskId
    }

    override fun onStart(taskInfo: TaskInfo) {
        Log.i(TAG, "Install application onStart(): taskId=${taskInfo.taskId}")
        
        // E.g. show indefinite progress as application installation task started
        showProgress()
    }

    override fun onProgress(progress: InstallationProgress) = with(progress) {
        Log.d(TAG, "Install application onProgress(): taskId=${taskId}, appId=${applicationId}, progress=${value}, action=$action")
        
        // E.g. show progress as application started donwload and installation
        showProgress()
        
        // 0 stands for download progress
        // 1 stands for install progress
        when (action) {
            0 -> updateDownloadProgress(value)
            1 -> updateInstallProgress(value)
        }
    }

    override fun onSuccess(result: InstallationResponse) {
        Log.d(TAG, "Install application onSuccess(): taskId=${result.taskId}, appId=${result.applicationId}, package=${result.packageName}")
        
        // E.g. hide progress as application is installed succesfully
        hideProgress()
    }

    override fun onError(error: Error) {
        Log.e(TAG, "Install application onError(): ${error.message}")
        hideProgress()
    }

    private fun showProgress() = progressBar?.visibility = View.VISIBLE
    private fun hideProgress() = progressBar?.visibility = View.GONE
}

// ...

Back to Top ⇧