3
我有一个免费的应用程序,其中还包含专业功能,如果他们购买我的应用程序在Android电子市场的专业密钥将提供给用户。我在专业应用程序中设置了一个接收器,并在主应用程序中设置了另一个接收器。当用户点击主应用程序中的“验证密钥”按钮时,意图会在关键应用程序中广播给接收方,然后启动IntentService以检查专业密钥许可证是否有效。然后,IntentService向主应用程序接收器广播包含LVL检查额外“响应”的意图。从意向服务的LVL许可证检查
我快到了。只有当我尝试在IntentService中执行LVL检查时,出现错误:
W/MessageQueue(2652): java.lang.RuntimeException: Handler{4052de20} sending message to a Handler on a dead thread
W/MessageQueue(2773): at com.android.vending.licensing.LicenseChecker$ResultListener.verifyLicense(LicenseChecker.java:207)
有什么建议吗?
的IntentService来源:
public class CheckerService extends IntentService {
private static final byte[] SALT = ....;
private static final String BASE64_PUBLIC_KEY = ...;
private String device_id;
public CheckerService() {
super("CheckerService");
}
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences data = getSharedPreferences("data", MODE_PRIVATE);
device_id = data.getString("device_id", null);
if (device_id == null) {
SharedPreferences.Editor editor = data.edit();
device_id = new DeviceId().generate(this);
editor.putString("device_id", device_id);
editor.commit();
}
ServerManagedPolicy smp = new ServerManagedPolicy(this,
new AESObfuscator(SALT, getPackageName(), device_id));
LicenseChecker checker = new LicenseChecker(this, smp, BASE64_PUBLIC_KEY);
checker.checkAccess(new LicenseCheckerCallback(){
public void allow() {
Intent i = new Intent();
i.setAction("com.mainapp.intent.action.LICENSE_RESPONSE");
i.putExtra("response", "LICENSE_OK");
sendBroadcast(i);
}
public void dontAllow() {
Intent i = new Intent();
i.setAction("com.mainapp.intent.action.LICENSE_RESPONSE");
i.putExtra("response", "LICENSE_NOT_OK");
sendBroadcast(i);
}
public void applicationError(ApplicationErrorCode errorCode) {
Intent i = new Intent();
i.setAction("com.mainapp.intent.action.LICENSE_RESPONSE");
i.putExtra("response", "LICENSE_ERROR");
sendBroadcast(i);
}});
}
@Override
public void onDestroy() {
super.onDestroy();
checker.onDestroy();
}
}
你能做到吗?需要更多的LVL示例 –