InAppUpdate not work proper ,the download process are done successful but app not install

时间秒杀一切 提交于 2020-02-03 10:07:27

问题


I implement Google in-app update on my app, I already added in my other app its work properly and its update my app also. but in my new app, I add its to same as oldest apk its follow all process and download also but not update the app.if anyone implements the proper in-app update code then please share and help.

can anyone tell ? its google side bug?

I already try all links and websites of in-app update reference for it.

Thanks in advance.


回答1:


Please try below code

private AppUpdateManager appUpdateManager;
private Task<AppUpdateInfo> appUpdateInfoTask;

/*--------- Check if update available ----------*/
appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
    @Override
    public void onSuccess(AppUpdateInfo result) {
        if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
                result.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
            Snackbar snackbar = Snackbar
                .make(coordinatorLayout, "Update Available", Snackbar.LENGTH_LONG)
                .setAction("Update", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        try {
                            appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, MainActivity.this, REQUEST_CODE_FLEXIBLE_UPDATE);
                        } catch (IntentSender.SendIntentException e) {
                            Log.e(TAG, "requestUpdate :: " + e.getMessage());
                            e.printStackTrace();
                        }
                    }
                });
            snackbar.show();
        }
    }
});

@Override
protected void onResume() {
    appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
        @Override
        public void onSuccess(AppUpdateInfo result) {
            if (result.installStatus() == InstallStatus.DOWNLOADED) {
                notifyUser();
            }
        }
    });
    super.onResume();
}

@Override
protected void onDestroy() {
    appUpdateManager.unregisterListener(MainActivity.this);
    super.onDestroy();
}

@Override
public void onStateUpdate(InstallState installState) {
    if (installState.installStatus() == InstallStatus.DOWNLOADED) {
        notifyUser();
    }
}

private void notifyUser() {
    Snackbar snackbar = Snackbar
        .make(coordinatorLayout, "Updated Successfully", Snackbar.LENGTH_LONG)
        .setAction("Install", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                appUpdateManager.completeUpdate();
                appUpdateManager.unregisterListener(MainActivity.this);
            }
        });
    snackbar.show();
}

I hope this can help you!

Thank You.



来源:https://stackoverflow.com/questions/59928329/inappupdate-not-work-proper-the-download-process-are-done-successful-but-app-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!