逐个显示一个Dialog,直到License检查通过

时间:2010-11-08 19:41:06

标签: java android android-lvl

我正在尝试实施LVL(Android许可验证库),但在许可检查失败时遇到问题。我弹出一个Dialog,它解释了许可证检查失败并向他们提供了两个按钮。一个按钮是“重试”,我想立即进行另一次检查或“购买应用程序”,重定向他们在App Market上购买应用程序。

当我点击重试按钮时,我可以通过记录消息看到我的许可检查被调用,我收到另一个“不允许”回调,我尝试再次显示上面的失败对话框(我看到onPrepareDialog()再次被调用)。

问题是第二个对话框实际上没有显示。因此,即使许可证检查失败,用户也可以使用该应用程序。为什么对话框不会一次又一次弹出?

我相信这是所有相关的代码:

private void checkLicense() {
    Log.d(TAG, "Checking License...");
    this.licenseChecker.checkAccess(this.licenseCheckerCallback);
}

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() { }

    public void dontAllow() {
        Log.d(TAG, "License resposne: Don't Allow");
        if (isFinishing())
            return; // Don't update UI if Activity is finishing.
        // Should not allow access. In most cases, the app should assume
        // the user has access unless it encounters this. If it does,
        // the app should inform the user of their unlicensed ways
        // and then either shut down the app or limit the user to a
        // restricted set of features.
        // In this example, we show a dialog that takes the user to Market.
        Log.d(TAG, "Showing No License Dialog");
        showDialog(DIALOG_NO_LICENSE_ID);
    }

    public void applicationError(ApplicationErrorCode errorCode) {
        if (isFinishing())
            return; // Don't update UI if Activity is finishing.
        // This is a polite way of saying the developer made a mistake
        // while setting up or calling the license checker library.
        showDialog(DIALOG_APPLICATION_ERROR_ID);
    }
}

protected Dialog onCreateDialog(int id) {
    Log.d(TAG, "Creating Dialog "+id);
    switch(id) {
    case DIALOG_NO_LICENSE_ID:
        return this.makeRetryPurchaseDialog(getString(R.string.no_license));
    case DIALOG_APPLICATION_ERROR_ID:
        return this.makeRetryPurchaseDialog(this.applicationErrorMessageForDialog);
    }
    return null;
}

private Dialog makeRetryPurchaseDialog(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(CalculatorTabActivity.this);
    builder.setMessage(message).setCancelable(false)
    .setPositiveButton("Retry", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            CalculatorTabActivity.this.checkLicense();
        }
    }).setNegativeButton("Purchase App", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            CalculatorTabActivity.this.openAppMarket();
        }
    });
    return builder.create();
}

1 个答案:

答案 0 :(得分:1)

就像一个想法一样,尝试明确地要求对话解雇:

...
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dissmissDialog(DIALOG_NO_LICENSE_ID);
        CalculatorTabActivity.this.checkLicense();
    }
})

此外,如果不起作用,请尝试使用removeDialog(DIALOG_NO_LICENSE_ID)代替dissmissDialog(DIALOG_NO_LICENSE_ID)

最后你在onPrepareDialog()中有什么代码(如果有的话)?