作者:手机用户2502905797 | 来源:互联网 | 2023-06-21 14:05
我正在使用fakeUpdateManager来测试应用内更新对话框,我将updateAvailable设置为10-10是我在playstore上的版本代码,并且我正在使用版本代码9构建app(Release)中的版本。
该应用正在商店内部测试中。
fakeUpdateManager = FakeAppUpdateManager(this)
fakeUpdateManager?.setUpdateAvailable(10)
// Returns an intent object that you use to check for an update.
fakeUpdateManager?.registerListener(installStateUpdatedListener)
fakeUpdateManager
?.appUpdateInfo
?.addOnSuccessListener { appUpdateInfo ->
Log.i("Mainactivity","${fakeUpdateManager?.isImmediateFlowVisible} appUpdateInfo : $appUpdateInfo")
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE || appUpdateInfo.updateAvailability()
== UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
// For a flexible update,use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
) {
// Request the update.
fakeUpdateManager?.startUpdateFlowForResult(
// Pass the intent that is returned by 'getappUpdateInfo()'.
appUpdateInfo,// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
AppUpdateType.IMMEDIATE,// The current activity making the update request.
this,// Include a request code to later monitor this update request.
APP_UPDATE_REQUEST_CODE
)
} else if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
// After the update is downloaded,show a notification
// and request user confirmation to restart the app.
popupsnackbarForCompleteUpdate()
}
}
以下代码用于侦听下载完成等信息,但是它没有用,因为updateFlow甚至还没有启动:
var installStateUpdatedListener: InstallStateUpdatedListener =
object : InstallStateUpdatedListener {
override fun onStateUpdate(state: InstallState) {
if (state.installStatus() == InstallStatus.DOWNLOADED) {
popupsnackbarForCompleteUpdate()
} else if (state.installStatus() == InstallStatus.INSTALLED) {
if (fakeUpdateManager != null) {
fakeUpdateManager?.unregisterListener(this)
}
} else {
Log.i(
"Mainactivity","InstallStateUpdatedListener: state: " + state.installStatus()
)
}
}
}
在appUpdateInfo内部-获取以下值
appUpdateInfo : AppUpdateInfo{packageName=com.property.ility,availableVersiOnCode=10,updateAvailability=2,installStatus=0,clientVersiOnStalenessDays=-1,bytesDownloaded=0,totalBytesToDownload=0,immediateUpdateIntent=PendingIntent{3f8812d: android.os.BinderProxy@df8e662},flexibleUpdateIntent=PendingIntent{af823f3: android.os.BinderProxy@df8e662}}
我已选中-fakeUpdateManager?.isImmediateFlowVisible
返回了我false
及以下是FakeUpdateManagerClass提供的方法。文档说:
/**
* Returns whether the user confirmation screen of the immediate update is visible to
the user.
*/
public boolean isImmediateFlowVisible() { throw new RuntimeException("Stub!"); }