gpt4 book ai didi

android - 应用内更新(立即)不重新启动应用

转载 作者:行者123 更新时间:2023-12-04 23:38:36 38 4
gpt4 key购买 nike

面临即时应用更新模式的问题。成功完成应用程序更新后,一切都关闭并且不重新启动应用程序。这就是问题所在。
但是android文档说:

A full screen user experience that requires the user to update andrestart the app in order to continue using the app. This UX is bestfor cases where an update is critical for continued use of the app.After a user accepts an immediate update, Google Play handles theupdate installation and app restart.

implementation 'com.google.android.play:core:1.9.1'
implementation 'com.google.android.play:core-ktx:1.8.1'
代码
class MainActivity : AppCompatActivity() {

companion object {
const val UPDATE_REQUEST_CODE = 112
const val TAG = "MainActivity"
}

private var appUpdateManager: AppUpdateManager? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<TextView>(R.id.tv_text).text = "Version " + BuildConfig.VERSION_NAME

// Returns an intent object that you use to check for an update.
appUpdateManager = AppUpdateManagerFactory.create(this)
}

private val listener: InstallStateUpdatedListener =
InstallStateUpdatedListener { installState ->
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
// After the update is downloaded, show a notification
// and request user confirmation to restart the app.
Log.d(TAG, "An update has been downloaded")
} else if (installState.installStatus() == InstallStatus.INSTALLED) {
Log.d(TAG, "An update has been installed")
}
}

override fun onStart() {
super.onStart()
checkAppVersionNew()
}

private fun checkAppVersionNew() {
val appUpdateInfoTask = appUpdateManager!!.appUpdateInfo
appUpdateInfoTask.addOnSuccessListener { result: AppUpdateInfo ->
if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && result.isUpdateTypeAllowed(
AppUpdateType.IMMEDIATE
)
) {
try {
Log.d(TAG, "An update available")
appUpdateManager!!.startUpdateFlowForResult(
result,
AppUpdateType.IMMEDIATE,
this,
UPDATE_REQUEST_CODE
)
} catch (e: SendIntentException) {
Log.d(TAG, "SendIntentException $e")
e.printStackTrace()
}
}
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

if (requestCode == UPDATE_REQUEST_CODE) {
when (resultCode) {
RESULT_OK -> {
Log.d(TAG, "Update success")
}
RESULT_CANCELED -> {
Log.d(TAG, "Update cancelled")
}
ActivityResult.RESULT_IN_APP_UPDATE_FAILED -> {
Log.d(TAG, "Update failed")
}
}
}
}
}

最佳答案

我遇到了这个问题,两天后我添加了

android:launchMode="singleTask"
到启动器 Activity 我用
ProcessPhoenix.triggerRebirth(this)
从 ProcessPhoenix 库 然后应用程序在更新后重新启动。

关于android - 应用内更新(立即)不重新启动应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66333491/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com