【问题标题】:How to use of In-app updates API in my app如何在我的应用中使用应用内更新 API
【发布时间】:2020-02-17 09:36:24
【问题描述】:

我发现了 2 个链接,我认为它会是正确的,但是在构建该代码之后它什么也没显示。我正在添加两个中的一个,并且最近构建了一个应用程序。

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

注意:-代码和链接有不同的代码。

代码

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();
    }

}

当我在调试中构建这段代码时,我什么也没发现。应用已在 Play-store 中发布时,此处未显示更新弹出窗口。

我想要什么

帮助在应用中使用应用内更新 API,如果您知道,请解释应用内更新 API 的流程。

【问题讨论】:

  • 您的 PlayStore 应用和调试应用中有什么 versionCode
  • 0.0.3 在 Play 商店中,我的应用在 0.0.2
  • 你为什么在链接中的代码中使用修改,任何具体原因,因为我也在使用this答案,它工作顺利。我也要求versionCode 而不是versionName
  • 对不起version name 我的版本代码分别是3和2。

标签: java android android-studio in-app-update


【解决方案1】:

你可以在这里找到实现:

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

对于版本代码实验,您可以使用 Play 商店内部测试功能

【讨论】:

  • 兄弟我想清楚地解释如何使用该代码,因为只有该代码我无法实现。
  • 是的,它已经在启动画面本身中实现了代码。
【解决方案2】:

您可以查看here 以供参考,看看它是否有效。

【讨论】:

    猜你喜欢
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多