4

我刚刚在我的应用程序中实现了 android 服务器检查。我正在使用 StrictPolicy 方法,因为盗版版本的下载量是市场上版本的 5 倍,因此我可能有点苦涩......无论如何,我基本上逐字将该方法编码到我的源代码中。但是,当我将开发人员控制台上的许可测试响应切换为许可时,我会看到未经许可的对话框。但是,在 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);
            }
        });
    }
}
4

2 回答 2

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" />
于 2011-04-25T19:46:37.243 回答
0

我也遇到过类似的问题,我通过在android manifest中的应用定义之前放置权限解决了,还要注意应用的版本,如果在市场上上传,你必须有相同的版本。

<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" >......
于 2013-04-09T16:32:43.610 回答