其他分享
首页 > 其他分享> > Android许可证检查直接进入applicationError(…)

Android许可证检查直接进入applicationError(…)

作者:互联网

我刚刚在我的应用中实现了android服务器检查.我正在使用StrictPolicy方法,因为我可能只是有点苦涩的盗版版本有5倍的下载量作为市场上的版本…无论如何,我基本上逐字逐句地编写了我的源代码.但是,当我将开发人员控制台上的许可证测试响应切换为Licensed时,我会收到未经许可的对话框.但是,在applicationError方法中,调用了dontAllow(),当我对此行进行注释时,未显示未许可的对话框.我究竟做错了什么?
这是我的MyLicenseCheckerCallback类.

我在onCreate中调用doCheck,在onResume中再调用doCheck.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler();
    mLicenseCheckerCallback = new MyLicenseCheckerCallback();

    // Construct the LicenseChecker with a Policy.
    mChecker = new LicenseChecker(
        this, new ServerManagedPolicy(this,
            new AESObfuscator(SALT, getPackageName(), deviceId)),
            BASE64_PUBLIC_KEY
            );
    doCheck();

    setContentView(R.layout.main);
    ...


private void doCheck() {
    mChecker.checkAccess(mLicenseCheckerCallback);
}

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
    public void allow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        // Should allow user access.
    }

    public void dontAllow() {
        if (isFinishing()) {
            // Don't update UI if Activity is finishing.
            return;
        }
        //Be as annoying as possible
        illegalDownload = new IllegalDownloadHandler(speedy.this);
        illegalDownload.show();
        illegalDownload.setOnDismissListener(new OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    Intent goToMarket = null;
                    goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.TimothyMilla.SpeedBoost"));
                    startActivity(goToMarket);
                    illegalDownload.dismiss();
                }
        });
        // Should not allow access. An app can handle as needed,
        // typically by informing the user that the app is not licensed
        // and then shutting down the app or limiting the user to a
        // restricted set of features.
        // In this example, we show a dialog that takes the user to Market.
        //showDialog(0);
        //onDestroy();
    }

    @Override
    public void applicationError(ApplicationErrorCode errorCode) {
        // TODO Auto-generated method stub
        dontAllow();
        //when I comment the above line out, the unlicensed dialog is not shown.
    }

    private void displayResult(final String result) {
        mHandler.post(new Runnable() {
            public void run() {
                //dontAllow();
                Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
                //setProgressBarIndeterminateVisibility(false);
            }
        });
    }
}

解决方法:

由于你没有更新我的评论,我的猜测……确保你:

1-正确复制您的公钥.

2-填充的deviceId,我想你是.只是确保因为上面的代码隐藏了该声明.但是因为它会给你带来编译错误,我相信你是.

3-更改了开发人员控制台中的响应代码(你说你有).

4-最后,您在Android清单文件中包含了适当的权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />

标签:android,android-lvl
来源: https://codeday.me/bug/20190610/1211226.html