【问题标题】:LVL license check from Intent Service来自 Intent Service 的 LVL 许可证检查
【发布时间】:2013-02-07 09:24:06
【问题描述】:

我有一个免费的应用程序,其中还包含专业功能,如果用户在 Android 市场上为我的应用程序购买专业密钥,他们就可以使用这些功能。我在 pro key 应用程序中设置了一个接收器,在主应用程序中设置了另一个接收器。当用户在主应用程序中单击“验证密钥”按钮时,一个意图被广播到密钥应用程序中的接收器,然后启动一个 IntentService 以检查 pro key 许可证是否有效。然后 IntentService 向主应用接收器广播一个意图,其中包含来自 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 示例

标签: android android-lvl intentservice


【解决方案1】:

我相信这个问题出在 IntentService 上。 IntentService 管理它自己的生命周期。本质上,它只是一个在非 UI 线程上运行的服务。服务在回调被处理之前就被销毁了,所以当回调发生时,没有任何东西可以“回调”到。

您可以尝试使用 START_STICKY 或 START_NOT_STICKY 在服务中运行它并自己管理生命周期。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-18
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多