1

我正在尝试ServerManagedPolicy在发布之前将其应用于我的应用程序。我已经byte[]为 Salt 定义了一个数组,得到了我的公钥,getPackageName()Settings.Secure.ANDROID_ID. 我还在我的主 Activity 中定义了一个私有类,其中包含一个LicenseCheckerCallback实现。让我们谈谈代码:

onCreate()

public void onCreate(Bundle savedInstanceState) { // line 47
    String deviceId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);

    checker = new LicenseChecker(this, new ServerManagedPolicy(this,
        new AESObfuscator(SALT, getPackageName(), deviceId)),
        BASE64_PUBLIC_KEY
    );
    checkerCallback = new MyCheckerCallback();

    checker.checkAccess(checkerCallback); // line 56

里面onDestroy()

@Override
protected void onDestroy() { // line 125
    super.onDestroy();
    checker.onDestroy();
}

MyCheckerCallback

private class MyCheckerCallback implements LicenseCheckerCallback {

    @Override
    public void allow(int reason) {
        if (isFinishing()) {
            return;
        }
        displayResult("Allow");
    }

    @Override
    public void dontAllow(int reason) {
        if (isFinishing()) {
            return;
        }
        displayResult("Don't allow");

        if (reason == ServerManagedPolicy.RETRY) {
            displayResult("Retry");
        } else {
            displayResult("Go to market");
        }
    }

    @Override
    public void applicationError(int errorCode) {

        displayResult((errorCode==LicenseCheckerCallback.ERROR_CHECK_IN_PROGRESS)+" progress");
        displayResult((errorCode==LicenseCheckerCallback.ERROR_INVALID_PACKAGE_NAME)+" package");
        displayResult((errorCode==LicenseCheckerCallback.ERROR_INVALID_PUBLIC_KEY)+" public");
        displayResult((errorCode==LicenseCheckerCallback.ERROR_MISSING_PERMISSION)+" permission");
        displayResult((errorCode==LicenseCheckerCallback.ERROR_NON_MATCHING_UID)+" uid");
        displayResult((errorCode==LicenseCheckerCallback.ERROR_NOT_MARKET_MANAGED)+" market");
    }
}

它完全基于开发者教程中的这个页面displayResult()显示带有消息的警报:

private void displayResult(String message) {
    AlertDialog dialog = new AlertDialog.Builder(this)
            .setIcon(android.R.drawable.ic_dialog_alert).setTitle("Status")
            .setMessage(message)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
    dialog.show();
}

设置完所有这些代码后,它会返回几个对话框:不允许和重试,在某些情况下,对应用程序施加一点压力后,它会在日志中显示此错误。

11-18 18:50:17.566: E/ActivityThread(23675): Activity com.package.test.TestActivity has leaked ServiceConnection com.google.android.vending.licensing.LicenseChecker@41a74ad0 that was originally bound here
11-18 18:50:17.566: E/ActivityThread(23675): android.app.ServiceConnectionLeaked: Activity com.package.test.TestActivity has leaked ServiceConnection com.google.android.vending.licensing.LicenseChecker@41a74ad0 that was originally bound here
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:965)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:859)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ContextImpl.bindService(ContextImpl.java:1191)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ContextImpl.bindService(ContextImpl.java:1183)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.content.ContextWrapper.bindService(ContextWrapper.java:394)
11-18 18:50:17.566: E/ActivityThread(23675):    at com.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:150)
11-18 18:50:17.566: E/ActivityThread(23675):    at com.package.test.TestActivity.onCreate(TestActivity.java:56)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.Activity.performCreate(Activity.java:5008)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3512)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ActivityThread.access$700(ActivityThread.java:130)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.os.Looper.loop(Looper.java:137)
11-18 18:50:17.566: E/ActivityThread(23675):    at android.app.ActivityThread.main(ActivityThread.java:4745)
11-18 18:50:17.566: E/ActivityThread(23675):    at java.lang.reflect.Method.invokeNative(Native Method)
11-18 18:50:17.566: E/ActivityThread(23675):    at java.lang.reflect.Method.invoke(Method.java:511)
11-18 18:50:17.566: E/ActivityThread(23675):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-18 18:50:17.566: E/ActivityThread(23675):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-18 18:50:17.566: E/ActivityThread(23675):    at dalvik.system.NativeStart.main(Native Method)

你以前遇到过这个错误吗?

4

1 回答 1

1

啊,只是我的运气。最后,我让它工作了。重试的问题在于,开发者控制台设置为在不久前(大约一个小时左右)返回常规答案,并且设备仅连接到 3G。它没有正确连接到服务器。一旦我转移到 Wi-Fi,响应开始变得更有用(NOT_MARKET_MANAGED在我的情况下,因为应用程序尚未上传)。

第二个问题,即记录的错误之一,只是在打开 Dialog 的情况下打开设备时出现的。

于 2012-11-18T22:27:23.940 回答