简体   繁体   中英

How to use of In-app updates API in my app

I found 2 links where I thought that it will be right but after the build of that code it showing nothing. I am adding one of two and recently build an 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 codes.

CODE

public class TestingActivity extends AppCompatActivity {

    private static final String TAG = "ResTest";

    private CoordinatorLayout coordinatorLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testing);
//        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() {
            @Override
            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>() {
            @Override
            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 {
                        appUpdateManager.registerListener(installStateUpdatedListener);
                        // Starts the desired update flow(HERE is FLEXIBLE update).
                        appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, TestingActivity.this, 100);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                } 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() {
            @Override
            public void onClick(View view) {
                appUpdateManager.completeUpdate();
            }
        });
        snackbar.show();
    }

}

When I build this code in debug I found nothing. No updation pop shown here while the 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.

You can find the implementation here:

https://github.com/im-ranu/Hurgi/blob/master/app/src/main/java/com/hurgistore/MainActivity.kt

for version code experiment you can use Play store internal testing feature

您可以在此处查看以供参考,看看它是否有效。

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