无需互联网连接的许可系统

发布于 2024-12-09 04:20:09 字数 465 浏览 0 评论 0原文

我正在测试 Android 的许可系统。确切地说,我刚刚使用 ServerManagedPolicy 编译了示例项目,我有一个问题: 如果我这样做:

Device's Internet=ON
Launch the app
Launch the check= Allow access
Device's Internet=OFF
Relaunch app and check= Allow access

好的,现在让我们看看问题:

Device's Internet=OFF
Launch the app
Launch the check= Don't allow access

从逻辑上讲,我不希望这样。因为如果用户在没有互联网的情况下启动该应用程序,即使该应用程序已获得许可,该应用程序也会被阻止。我该如何解决这个问题?我的应用程序需要连接到互联网才能工作,因此延迟检查没有问题

I'm testing the licensing system for android. Exactly I just compiled the sample project with ServerManagedPolicy and I have a question about it:
If I do:

Device's Internet=ON
Launch the app
Launch the check= Allow access
Device's Internet=OFF
Relaunch app and check= Allow access

Ok now lets see the problem:

Device's Internet=OFF
Launch the app
Launch the check= Don't allow access

Logically I don't want that. Because the app will be blocked if the user launches the app without Internet, even if it was licensed. How can I solve that? My application needs to be connected to the Internet for working so there's no problem in delaying that check

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巴黎盛开的樱花 2024-12-16 04:20:09

您可以使用带有handleResponse()的自定义LicenseValidator类,仅当策略返回LicenseResponse.NOT_LICENSED时,该类才会在许可证检查器回调上调用dontAllow(),并在所有其他情况下(包括网络错误)调用allow()。

 public class LicenseValidator {
...
    public void handleResponse(LicenseResponse response, ResponseData rawData) {
        mPolicy.processServerResponse(response);
        if (mPolicy.allowAccess()) {
            mCallback.allow();
        } else if (response == LicenseResponse.NOT_LICENSED) {
            mCallback.dontAllow();
        }
    }

并使用自定义策略而不是 ServerManagedPolicy:

public class MyPolicy {
private LicenseResponse mLastResponse;

public MyPolicy(Activity activity) {
    mLastResponse = LicenseResponse.RETRY;
}

public void processServerResponse(LicenseResponse response) {
    mLastResponse = response;
}

public boolean allowAccess() { 
    return (LicenseResponse.LICENSED.equals(mLastResponse));
}

}

这只是我所做的,而且效果很好。

You may use a custom LicenseValidator class with a handleResponse() that would call dontAllow() on the License checker callback only when the policy returns LicenseResponse.NOT_LICENSED, and allow() in all other cases including network error.

 public class LicenseValidator {
...
    public void handleResponse(LicenseResponse response, ResponseData rawData) {
        mPolicy.processServerResponse(response);
        if (mPolicy.allowAccess()) {
            mCallback.allow();
        } else if (response == LicenseResponse.NOT_LICENSED) {
            mCallback.dontAllow();
        }
    }

And use also a custom Policy instead of the ServerManagedPolicy:

public class MyPolicy {
private LicenseResponse mLastResponse;

public MyPolicy(Activity activity) {
    mLastResponse = LicenseResponse.RETRY;
}

public void processServerResponse(LicenseResponse response) {
    mLastResponse = response;
}

public boolean allowAccess() { 
    return (LicenseResponse.LICENSED.equals(mLastResponse));
}

}

This is petty much what I did and it works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文