Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 显示一个又一个对话框,直到许可证检查通过_Java_Android_Android Lvl - Fatal编程技术网

Java 显示一个又一个对话框,直到许可证检查通过

Java 显示一个又一个对话框,直到许可证检查通过,java,android,android-lvl,Java,Android,Android Lvl,我正在尝试实现LVL(Android许可验证库),但在许可检查失败时遇到了问题。我弹出一个对话框,解释许可证检查失败,并显示两个按钮。其中一个按钮是“重试”,我想立即进行另一次检查,或者是“购买应用程序”,将他们重定向到应用程序市场上购买应用程序 当我点击“重试”按钮时,我可以从日志消息中看到我的许可检查被调用,我收到另一个“不允许”回调,我尝试再次显示上面的失败对话框(我看到onPrepareDialog()再次被调用) 问题是第二个对话框实际上没有显示。因此,即使许可证检查失败,用户也可以使

我正在尝试实现LVL(Android许可验证库),但在许可检查失败时遇到了问题。我弹出一个对话框,解释许可证检查失败,并显示两个按钮。其中一个按钮是“重试”,我想立即进行另一次检查,或者是“购买应用程序”,将他们重定向到应用程序市场上购买应用程序

当我点击“重试”按钮时,我可以从日志消息中看到我的许可检查被调用,我收到另一个“不允许”回调,我尝试再次显示上面的失败对话框(我看到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();
}

作为一个想法,请尝试明确呼吁取消对话:

...
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dissmissDialog(DIALOG_NO_LICENSE_ID);
        CalculatorTabActivity.this.checkLicense();
    }
})
此外,如果这不起作用,请尝试使用
removeDialog(DIALOG\u NO\u LICENSE\u ID)
而不是
dismissiondialog(DIALOG\u NO\u LICENSE\u ID)


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

您试过调试它吗?应用程序错误呼叫?onCreateDialog呢?它有正确的身份证吗?谢谢!removeDialog()成功了。我的假设是发生了某种竞争情况,在第一个对话框被取消之前,我的许可证检查代码试图再次显示该对话框。