无法使用 Play 核心库提供的支持应用内更新来更新应用

问题描述

我只是想在 google play 核心库 API 提供的应用更新服务中实现。

将新版本的应用发布到内部测试轨道后,我在 Play 商店中获得了应用的更新版本

enter image description here

但是,我无法在同一页面上看到“更新”按钮

enter image description here

此外,应用程序无法根据代码的实现进行更新。 请帮我解决这个问题。

private AppUpdateManager appUpdateManager;

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

        appUpdateManager = AppUpdateManagerFactory.create(this);
        InAppUpdate.setImmediateUpdate(appUpdateManager,this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        InAppUpdate.setImmediateUpdateOnResume(appUpdateManager,this);
    }
}

public class InAppUpdate {

    public static int REQUEST_APP_UPDATE = 302;

    public static void setImmediateUpdate(AppUpdateManager appUpdateManager,Activity activity) {

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            // Checks that the platform will allow the specified type of update.
                            if ((appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
                                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                                // Request the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,AppUpdateType.IMMEDIATE,activity,REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printstacktrace();
                                }
                            }
                        });
    }

    public static void setImmediateUpdateOnResume(AppUpdateManager appUpdateManager,Activity activity) {

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            if (appUpdateInfo.updateAvailability()
                                    == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                                // If an in-app update is already running,resume the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printstacktrace();
                                }
                            }
                        });
    }

    public static void setFlexibleupdate(AppUpdateManager appUpdateManager,Activity activity) {

        InstallStateUpdatedListener installStateUpdatedListener = installState -> {
            if (installState.installStatus() == InstallStatus.DOWNLOADED) {
                Snackbar snackbar =
                        Snackbar.make(
                                activity.findViewById(android.R.id.content),activity.getString(R.string.in_app_snack_bar_message),Snackbar.LENGTH_INDEFINITE);
                //lambda operation used for below action
                snackbar.setAction(activity.getString(R.string.in_app_snack_bar_action_title),view ->
                        appUpdateManager.completeUpdate());
                snackbar.setActionTextColor(activity.getResources().getColor(R.color.in_app_snack_bar_text_color))
                ;
                snackbar.show();
            } else
                Log.e("UPDATE","Not downloaded yet");
        };

        appUpdateManager
                .getAppUpdateInfo()
                .addOnSuccessListener(
                        appUpdateInfo -> {

                            // Checks that the platform will allow the specified type of update.
                            if ((appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
                                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                                // Request the update.
                                try {
                                    appUpdateManager.startUpdateFlowForResult(
                                            appUpdateInfo,AppUpdateType.FLEXIBLE,REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printstacktrace();
                                }
                            }
                        });

        appUpdateManager.registerListener(installStateUpdatedListener);
    }

    public static void setFlexibleupdateOnResume(AppUpdateManager appUpdateManager,REQUEST_APP_UPDATE);
                                } catch (IntentSender.SendIntentException e) {
                                    e.printstacktrace();
                                }
                            }
                        });
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)