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

2024-01-30

我刚刚在我的应用程序中实现了 android 服务器检查。我使用 StrictPolicy 方法是因为我可能对盗版版本的下载量是市场版本的 5 倍感到有点苦恼……无论如何,我基本上将该方法逐字编码到我的源代码中。但是,当我将开发人员控制台上的许可证测试响应切换为“已许可”时,我会看到“未许可”对话框。但是,在 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" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 许可证检查直接进入 applicationError(...) 的相关文章

随机推荐