38 lines
1.5 KiB
Kotlin
38 lines
1.5 KiB
Kotlin
package com.expapp.trigger.update
|
|
|
|
import android.content.BroadcastReceiver
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.content.pm.PackageInstaller
|
|
import android.os.Build
|
|
import android.widget.Toast
|
|
|
|
class InstallStatusReceiver : BroadcastReceiver() {
|
|
override fun onReceive(context: Context, intent: Intent) {
|
|
val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)
|
|
when (status) {
|
|
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
|
val confirmationIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
intent.getParcelableExtra(Intent.EXTRA_INTENT, Intent::class.java)
|
|
} else {
|
|
@Suppress("DEPRECATION")
|
|
intent.getParcelableExtra(Intent.EXTRA_INTENT)
|
|
}
|
|
if (confirmationIntent != null) {
|
|
confirmationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
context.startActivity(confirmationIntent)
|
|
}
|
|
}
|
|
PackageInstaller.STATUS_SUCCESS -> {
|
|
Toast.makeText(context, "Update installed successfully!", Toast.LENGTH_SHORT).show()
|
|
}
|
|
else -> {
|
|
val message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE)
|
|
if (!message.isNullOrBlank()) {
|
|
Toast.makeText(context, "Update: $message", Toast.LENGTH_SHORT).show()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|