我正在尝试在发布之前将ServerManagedPolicy
应用于我的应用程序。我为Salt定义了一个byte[]
数组,得到了我的公钥,得到了getPackageName()
和来自Settings.Secure.ANDROID_ID
的设备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");
}
}
它完全基于开发人员教程中的page。 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)
你以前遇到过这个错误吗?
答案 0 :(得分:1)
NOT_MARKET_MANAGED
,在我的情况下,因为应用尚未上传。)
第二个问题,即记录的错误1,就在打开对话框时打开设备时出现。