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

时间:2011-04-03 01:08:23

标签: android android-lvl

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

我在onCreate中调用doCheck,然后在onResume中调用。

@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);
            }
        });
    }
}

2 个答案:

答案 0 :(得分:8)

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

1-正确复制了您的公钥。

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

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

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

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

答案 1 :(得分:0)

我遇到了类似的问题,我通过将权限放在android清单中的应用程序定义之前来解决它,也要小心应用程序的版本,如果在市场上传,你必须拥有相同的版本。

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >......