Home » Java » java – How to use of In-app updates API in my app-Exceptionshub

java – How to use of In-app updates API in my app-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I found 2 links where I thought that it will be right but after build of that code it showing nothing.I am adding one of two and recently build app.

Link have accepted answer but it is not running in my app and I am unable to find what I missed

Note: Code and link have different code.


public class TestingActivity extends AppCompatActivity {

    private static final String TAG = "ResTest";

    private CoordinatorLayout coordinatorLayout;
    protected void onCreate(Bundle savedInstanceState) {
//        coordinatorLayout = findViewById(R.id.res_test);
        // Initialize AppUpdateManager. AppUpdateManager helps to Manages operations that allow your app to initiate its own updates.
        final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(TestingActivity.this);
        // Requests the update availability for the current app, an intent to start an update flow, and, if applicable, the state of updates currently in progress.
        Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
        // InstallStateUpdatedListener is listener that used to monitor updates installs.
        final InstallStateUpdatedListener installStateUpdatedListener = new InstallStateUpdatedListener() {
            public void onStateUpdate(InstallState installState) {
                // If successfully download then call popupSnackBarForCompleteUpdate() to show snackbar of successfully downloaded latest update.
                if (installState.installStatus() == InstallStatus.DOWNLOADED) {
//                    popupSnackBarForCompleteUpdate(coordinatorLayout, appUpdateManager);
                    Toast.makeText(TestingActivity.this, String.valueOf( appUpdateManager.completeUpdate()), Toast.LENGTH_SHORT).show();
        // Checks that the platform will allow the specified type of update.
        appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
            public void onSuccess(AppUpdateInfo appUpdateInfo) {
                if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
                        // As it's flexible update so use FLEXIBLE.
                        appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {

//                    Log.d(TAG, "app here 1");

                    // Request the update.
                    try {
                        // Starts the desired update flow(HERE is FLEXIBLE update).
                        appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, TestingActivity.this, 100);
                    } catch (IntentSender.SendIntentException e) {
                } else {
                    if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                        popupSnackBarForCompleteUpdate(coordinatorLayout, appUpdateManager);

    private static void popupSnackBarForCompleteUpdate(View view, final AppUpdateManager appUpdateManager) {
        Snackbar snackbar = Snackbar.make(view, "An update has just been downloaded.", Snackbar.LENGTH_INDEFINITE);

        snackbar.setAction("RESTART", new View.OnClickListener() {
            public void onClick(View view) {


When I build this code in debug I found nothing. No updation pop shown here while app has been published in play-store.

What I want

Help to use In-App updates API in app and if you know so please explain a flow of in app updates API.

How to&Answers: