开发者

Licensing system without Internet connection

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开发者_JS百科 for working so there's no problem in delaying that check


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜