Android-无法安装动态功能

时间:2019-06-11 10:44:20

标签: java android module bundle

当前,我正在尝试将现有应用转换为Android捆绑式应用。我已经对其进行了模块化,所有功能都可以正常运行,但是其他模块(作为动态功能)无法正确安装。

登录后,我要安装缺少的模块。看起来像这样:

public void installModules(int rechthoehe, final Activity ac){
        if(rechthoehe>=1){
            System.out.println("INSTALL schueler");
            installModule("schueler",ac);
        }
        if(rechthoehe>=2){
            System.out.println("INSTALL lehrer");
            installModule("lehrer",ac);
        }
        if(rechthoehe>=3){
            System.out.println("INSTALL itteam");
            installModule("itteam",ac);
        }
    }

    public void installModule(final String moduleName, final Activity ac){
        final ProgressDialog dialog = new ProgressDialog(ac);
        dialog.setTitle(ac.getString(www.amg_witten.de.apptest.R.string.module_download_dialog_title));
        dialog.setMessage(ac.getString(www.amg_witten.de.apptest.R.string.module_download_dialog_pending));
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.show();
        SplitInstallManager splitInstallManager = SplitInstallManagerFactory.create(ac);

        SplitInstallRequest request = SplitInstallRequest.newBuilder()
                .addModule(moduleName)
                .build();

        SplitInstallStateUpdatedListener listener = new SplitInstallStateUpdatedListener() {
            @Override
            public void onStateUpdate(final SplitInstallSessionState state) {
                switch (state.status()){
                    case SplitInstallSessionStatus.DOWNLOADING:
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                dialog.setMessage(ac.getString(R.string.module_download_dialog_downloading));
                                dialog.setMax((int) state.totalBytesToDownload());
                                dialog.setProgress((int) state.bytesDownloaded());
                            }
                        });
                        break;
                    case SplitInstallSessionStatus.DOWNLOADED:
                        dialog.setMessage(ac.getString(R.string.module_download_dialog_downloaded));
                        dialog.setMax(0);
                        dialog.setProgress(0);
                        break;
                    case SplitInstallSessionStatus.INSTALLING:
                        dialog.setMessage(ac.getString(R.string.module_download_dialog_installing));
                        dialog.setIndeterminate(true);
                        break;
                }
            }
        };

        splitInstallManager.registerListener(listener);
        splitInstallManager.startInstall(request)
                .addOnSuccessListener(new OnSuccessListener<Integer>(){
                    @Override
                    public void onSuccess(Integer integer) {
                        System.out.println("SUCCESS at "+moduleName+"!!!"+integer);

                        SplitInstallManager splitInstallManager =
                                SplitInstallManagerFactory.create(ac);
                        Set<String> installedModules = splitInstallManager.getInstalledModules();
                        System.out.println("AfterInstall after "+moduleName+Arrays.deepToString(installedModules.toArray()));
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception e) {
                        e.printStackTrace();
                        if(e instanceof SplitInstallException){
                            System.out.println(((SplitInstallException) e).getErrorCode());
                            System.out.println(e.getCause());
                        }
                    }
                });
    }

它输出以下内容:

2019-06-11 12:29:24.512 8496-8496/? I/System.out: INSTALL schueler
2019-06-11 12:29:24.542 8496-8496/? I/System.out: INSTALL lehrer
2019-06-11 12:29:24.563 8496-8496/? I/System.out: INSTALL itteam
2019-06-11 12:29:24.704 8496-8496/? I/System.out: SUCCESS at schueler!!!0
2019-06-11 12:29:24.707 8496-8496/? I/System.out: AfterInstall after schueler[schueler, lehrer]
2019-06-11 12:29:24.708 8496-8496/? I/System.out: SUCCESS at lehrer!!!0
2019-06-11 12:29:24.713 8496-8496/? I/System.out: AfterInstall after lehrer[schueler, lehrer]
2019-06-11 12:29:24.987 8496-8496/? I/System.out: 3
2019-06-11 12:29:24.990 8496-8496/? I/System.out: Starting..[schueler, lehrer]
2019-06-11 12:29:25.761 8496-8496/? I/System.out: SUCCESS at itteam!!!12
2019-06-11 12:29:25.767 8496-8496/? I/System.out: AfterInstall after itteam[schueler, lehrer]

如您所见,尚未安装itteam模块。其他两个模块也未从此功能安装,我以rechthoehe=2(Lehrer)身份登录,然后更新了该应用程序。

感谢您的帮助!

0 个答案:

没有答案