我已经在Android中实现了新出现的功能,这些功能是使用Flexible进行的应用内更新。我已经引用了官方链接,但在应用下载完成后,我仍然遇到一些问题。
AppUpdateManager appUpdateManager;
private void checkAppUpdateAvailability()
{
appUpdateManager = AppUpdateManagerFactory.create(this);
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo appUpdateInfo) {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(FLEXIBLE)) {
// Request the update.
try {
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
FLEXIBLE,
// The current activity making the update request.
MainActivity.this,
// Include a request code to later monitor this update request.
100);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 100) {
if (resultCode != RESULT_OK) {
Log.d("JNiS","Update flow failed! Result code: " + resultCode);
// If the update is cancelled or fails,
// you can request to start the update again.
}
}
}