我正在尝试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)
你以前遇到过这个错误吗?