【问题标题】:Licensing system without Internet connection没有互联网连接的许可系统
【发布时间】:2011-10-07 10:10:08
【问题描述】:

我正在测试 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

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

【问题讨论】:

    标签: java android google-play android-lvl


    【解决方案1】:

    您可以使用带有 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));
    }
    

    }

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-01
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 2012-12-24
      • 1970-01-01
      相关资源
      最近更新 更多