Я прошел через шаги, упомянутые здесь Поддержка обновлений в приложении .
Я загрузил приложение в игровой магазин, чтобы проверить функцию обновления приложения.
Ниже приведен фрагмент кода:
class MainActivity : AppCompatActivity() {
val REQUEST_CODE_UPDATE = 1001
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
Snackbar.make(view, "Checking for update", Snackbar.LENGTH_LONG)
.show()
checkForUpdate()
}
}
override fun onResume() {
super.onResume()
val updateManager = AppUpdateManagerFactory.create(this)
updateManager.appUpdateInfo
.addOnSuccessListener {
if (it.updateAvailability() ==
UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
updateManager.startUpdateFlowForResult(
it,
IMMEDIATE,
this,
REQUEST_CODE_UPDATE)
}
}
}
fun checkForUpdate(){
// Creates instance of the manager.
val appUpdateManager = AppUpdateManagerFactory.create(this)
// Checks that the platform will allow the specified type of update.
appUpdateManager.appUpdateInfo.addOnSuccessListener {
if (it.availableVersionCode() == UpdateAvailability.UPDATE_AVAILABLE &&
it.isUpdateTypeAllowed(IMMEDIATE))
{
appUpdateManager.startUpdateFlowForResult(
it,
IMMEDIATE,
this,
REQUEST_CODE_UPDATE)
}
}
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_CODE_UPDATE) {
if (requestCode != RESULT_OK) {
Log.e("System out", "Update flow failed! Result code: " + resultCode)
// If the update is cancelled or fails,
// you can request to start the update again.
}
}
}
}
Файл моего Gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.play:core:1.5.0'
}
Когда я отлаживаю код ниже, я выше кода, каждый раз, когда я получаю, если (appUpdateInfo.availableVersionCode() == 0(UpdateAvailability.UNKNOWN)
Журналы:
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : requestUpdateInfo(com.inappupdate)
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : requestUpdateInfo(com.inappupdate)
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : Initiate binding to the service.
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : Waiting to bind to the service.
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.installservice.DevTriggeredUpdateService})
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : linkToDeath
2019-05-09 16:11:23.534 22537-23035/com.inappupdate I/PlayCore: UID: [10280] PID: [22537] OnRequestInstallCallback : onRequestInfo
I/PlayCore: UID: [10280] PID: [22537] AppUpdateService : Unbind from service.
I/PlayCore: UID: [10280] PID: [22537] OnRequestInstallCallback : onRequestInfo
Итак, если кто-нибудь может подсказать мне, как я могу решить эту ошибку.