简体   繁体   中英

Google Play / App Store: force update app

Say, a user has installed an app. Then I have released a new version to the store. Now I want all users to have the updated app before they'll continue using it.

Of course, I can put some flag on the server side, which will prevent old versions from being used, but this assumes that the user has to open the app first, then update it, then use it. Or, I can create some push notification, which will remind all users at once to update. But I have never seen such notifications, so I assume this is not the conventional way.

So, is there a conventional way to do that? How do I force all apps to get updated right after a new version is released? And preferably, while the app is in the background.

There is no way. The user controls their hardware and may not want to update. And the Play Store itself has controls on when it updates (it prefers to do so overnight, it prefers to do so on wifi rather than cellular data). If you want this, the thing to do is to do a version check on the server and send down a code which will either have the app update itself from your server, or have it tell the user to update it from Play.

You can use an api that need's to update with play store version. And then check with installed version. If it's older than your play store version then go to play store before any others activities and force to update it. I am using retrofit2 to call api.

    private int versionCode = BuildConfig.VERSION_CODE;
    private String versionName = BuildConfig.VERSION_NAME;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        GetAppVersion();
}

 private void GetAppVersion() {
        final DatabaseManager dm = new DatabaseManager(this);

        Retrofit retrofit = RetrofitSingleton.getInstance(getBaseContext());

        final CommonApiInterface commonApiInterface = retrofit.create(CommonApiInterface.class);

        commonApiInterface.GetAppCurrentVersion().enqueue(new Callback<AppVersionModel>() {
            @Override
            public void onResponse(Call<AppVersionModel> call, Response<AppVersionModel> response) {
                Boolean b = dm.update_TrackAppVersion(Integer.valueOf(response.body().getVersionCode()),response.body().getVersionName());
                if (versionCode < Integer.valueOf(response.body().getVersionCode())) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=YOUR PACKAGE NAME"));
                    startActivity(intent);
                }
            }

            @Override
            public void onFailure(Call<AppVersionModel> call, Throwable t) {
                Log.d("Error", "onFailure: "+t);
            }
        });
    }

There actually is a way (released quite recently) to do it – using the Android in-app updates API . The cool thing is that the update process can be finished without the user even leaving the app.

You can fetch app update info using AppUpdateManager and then use the in-app updates API to initiate either a flexible update (prompts the user to update in-app and allows downloading in the background, but lets the user choose whether or not to update) or an immediate update (full screen view that doesn't let the user proceed before updating).

The official in-app updates guide has sample code and instructions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM