我看到当我打开旧版本的Tokopedia应用时,该对话框始终出现。 Tokopedia建议我更新该应用。
对话框为我提供了两种更新应用程序的方法:
如果我选择 Lain Kali (取消),则该对话框将在下一个打开的应用中再次出现。但是,如果我选择第二个选项,则会打开Play商店并看到此行为:
它确实会在后台更新,直到我的设备连接到Wi-Fi。
我想模仿与Tokopedia相同的操作,因为我的应用程序的某些版本包含严重错误。我想为用户提供更好的用户体验。
您知道如何显示上面的对话框吗?
答案 0 :(得分:3)
可以使用Google提供的应用内更新。
应用内更新仅适用于运行Android 5.0(API级别21)或更高版本的设备,并且要求您使用Play Core库1.5.0或更高版本。有两种类型:1.Flexible和2. Instant。
点击此链接并根据您的要求实施应用内更新。
https://developer.android.com/guide/app-bundle/in-app-updates
答案 1 :(得分:1)
您可以使用 Support in-app updates
它仅可用于 Android 5.0(API级别21)或更高版本。
UX中有两种类型的更新可用于应用程序内更新:
let array = ["Anand", "Ani", "Dan", "Eion", "Harsh", "Jocab", "Roshan", "Stewart"]
let searchText = "R"
let filteredArray = array.filter({$0.lowercased().contains(searchText.lowercased())})
let sortedArray = filteredArray.sorted { (str1, str2) -> Bool in
if let index1 = str1.lowercased().firstIndex(of: Character(searchText.lowercased())), let index2 = str2.lowercased().firstIndex(of: Character(searchText.lowercased())) {
return index1 < index2
}
return false
}
print(sortedArray) //["Roshan", "Harsh", "Stewart"]
答案 2 :(得分:1)
好的,这是@akshay_shahane要求的完整代码。
首先,将此行添加到您应用的build.gradle
上:
dependencies {
implementation 'com.google.android.play:core:1.6.1'
}
在您的活动中:
class MainActivity : AppCompatActivity(), InstallStateUpdatedListener {
private val appUpdateManager by lazy {
AppUpdateManagerFactory.create(this).also { it.registerListener(this) }
}
override fun onDestroy() {
if (Build.VERSION.SDK_INT >= 21) {
appUpdateManager.unregisterListener(this)
}
super.onDestroy()
}
override fun onResume() {
super.onResume()
if (Build.VERSION.SDK_INT >= 21) {
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
// If the update is downloaded but not installed, notify the user to complete the update.
if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
popupSnackbarForCompleteUpdate()
} else if (it.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
&& it.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
appUpdateManager.startUpdateFlowForResult(it, AppUpdateType.IMMEDIATE, this, REQUEST_CODE_UPDATE_APP)
}
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == ActivityResult.RESULT_IN_APP_UPDATE_FAILED && requestCode == REQUEST_CODE_UPDATE_APP) {
Toast.makeText(this, "Update failed", Toast.LENGTH_SHORT).show()
}
}
override fun onStateUpdate(state: InstallState) {
when (state.installStatus()) {
InstallStatus.DOWNLOADED -> popupSnackbarForCompleteUpdate()
InstallStatus.REQUIRES_UI_INTENT -> {
Snackbar.make(findViewById(R.id.activity_main_layout),
"To perform the installation, a Play Store UI flow needs to be started.",
Snackbar.LENGTH_LONG
).show()
}
else -> {
val stateString = when (state.installStatus()) {
InstallStatus.FAILED -> "failed"
InstallStatus.PENDING -> "pending"
InstallStatus.DOWNLOADING -> "downloading"
InstallStatus.INSTALLING -> "installing"
InstallStatus.INSTALLED -> "installed"
InstallStatus.CANCELED -> "canceled"
else -> null
}
if (stateString != null) {
Snackbar.make(findViewById(R.id.activity_main_layout),
"An update is $stateString.",
Snackbar.LENGTH_SHORT
).show()
}
}
}
}
private fun popupSnackbarForCompleteUpdate() {
Snackbar.make(findViewById(R.id.activity_main_layout),
"An update is ready to install.",
Snackbar.LENGTH_INDEFINITE
).apply {
setAction("INSTALL") { appUpdateManager.completeUpdate() }
show()
}
}
@RequiresApi(21)
fun checkUpdateViaGooglePlay() {
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
when (appUpdateInfo.updateAvailability()) {
UpdateAvailability.UPDATE_AVAILABLE -> {
if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo, AppUpdateType.FLEXIBLE, this, REQUEST_CODE_UPDATE_APP)
} else if (appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo, AppUpdateType.IMMEDIATE, this, REQUEST_CODE_UPDATE_APP)
}
}
UpdateAvailability.UPDATE_NOT_AVAILABLE -> {
Toast.makeText(this, R.string.no_updates_found, Toast.LENGTH_SHORT).show()
}
}
}.addOnFailureListener {
Toast.makeText(this, R.string.error_check_update, Toast.LENGTH_SHORT).show()
}
}
companion object {
const val REQUEST_CODE_UPDATE_APP = 8
}
}