gpt4 book ai didi

java - Android PlayStore 'InAppUpdate' 绝对强制升级(必须立即升级,不能取消任何选项)

转载 作者:行者123 更新时间:2023-12-05 00:00:42 55 4
gpt4 key购买 nike

我有下面的代码,我已经成功地实现了 InAPPUpdate 代码,根据下面的屏幕截图,它工作正常。但是,在此实现中,用户仍然可以使用 (X) 关闭按钮取消 InAppUpdate,并且在下载应用更新时用户仍然可以取消更新。

我的问题是有没有一种方法可以绝对强制最终用户更新应用程序?除非他们更新,否则我需要阻止他们使用该应用。

注意:(请不要问为什么要强制不是讨论的问题)

enter image description here

public class MainActivity extends BaseActivity implements TabLayout.OnTabSelectedListener, MainView {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//check for updates
validateAppUpdate();
}

//in app updates
private void validateAppUpdate() {
// Creates instance of the manager.
appUpdateManager = AppUpdateManagerFactory.create(getBaseContext());

// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo appUpdateInfo) {

Log.e("AVAILABLE_VERSION_CODE", appUpdateInfo.availableVersionCode()+"");
Log.e("AVAILABLE_VERSION_CODE_2", appUpdateInfo.updateAvailability()+"");
//Log.e("html", "Error loading html/index.html", e);
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
// Request the update.

try {
appUpdateManager.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.
MainActivity.this,
// Include a request code to later monitor this update request.
UPDATE_REQUEST_CODE);
} catch (IntentSender.SendIntentException ignored) {

}
}else{
System.out.println("No Update Available.");
}
}
});

appUpdateManager.registerListener(installStateUpdatedListener);

}
//lambda operation used for below listener
InstallStateUpdatedListener installStateUpdatedListener = installState -> {
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
popupSnackbarForCompleteUpdate();
}
};


private void popupSnackbarForCompleteUpdate() {

Snackbar snackbar =
Snackbar.make(
findViewById(android.R.id.content),
"Update almost finished!",
Snackbar.LENGTH_INDEFINITE);
//lambda operation used for below action
snackbar.setAction(this.getString(R.string.APP_NAME), view ->
appUpdateManager.completeUpdate());
snackbar.setActionTextColor(getResources().getColor(R.color.browner));
snackbar.show();
}

最佳答案

你需要在你的类中覆盖 onActivityResult() 来扩展 Activity ,如下所示:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
validateAppUpdate();
}
}

这将运行 validateAppUpdate() 直到应用更新。

关于java - Android PlayStore 'InAppUpdate' 绝对强制升级(必须立即升级,不能取消任何选项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70576521/

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