且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

许可检查长寿"激活"状态。如何频繁的是太多的用户?

更新时间:2022-10-23 18:56:59

只是我的两分钱,你可以定义一段时间,你想查询(可以说3天)。检查许可证后3天内,如果没有网络,继续让用户使用它可以说一个星期最多否则该应用程序将无法充分发挥作用。或者只是保持它充分发挥作用,直到有一次一个连接,然后就可以检查并重置您的时间戳。当你告诉它的许可证检查程序将只检查。

我可以澄清如果需要的话!

好运气

My app is a kind of a pocket guide with some data for the whole year. I'm assuming users will use the program at least once with Internet access to activate the license. Or at least that's my understanding of how the Android licensing system works. I'm using ServerManagedPolicy.

Does it check periodically for the license? Is there any way that I can control this? I don't want my users to be in the middle of nowhere, with an app already and previously activated and suddenly after 1 week, 1 month, 1 year etc. the app starts limiting the usability of the app itself because the license couldn't be verified again. My app is going to be used in remote places with erratic net access (can't be taken for granted all the time) by people who will live there for weeks, maybe months.

I feel I should at least warn them that they will be asked every X weeks to do that. Is the license system even that draconian?

I know I can handle the errors with the ERROR_CONTACTING_SERVER flag, on the applicationError void of LicenseCheckerCallback. Is the "VT" response always the same (can't test this on a test account/my account)? I was just curious about how you guys treat this situation on your own real life apps. Am I missing something here? For some reason I'm feeling I am. Is there any "catch"?

// EDITED:

Here is the code I'm trying right now:

// ServerManagedPolicy.java
private void setValidityTimestamp(String validityTimestamp) {
    Long lValidityTimestamp;
    try {
        lValidityTimestamp = Long.parseLong(validityTimestamp);
    } catch (NumberFormatException e) {
        // No response or not parsable, expire in one minute.
        Log.w(TAG, "License validity timestamp (VT) missing, caching for a minute");
        lValidityTimestamp = System.currentTimeMillis() + MILLIS_PER_MINUTE;
        validityTimestamp = Long.toString(lValidityTimestamp);
    }
    // added by me--->

    private static long maxLicense = 1000 * 3600 * 24 * 30; // ~ roughly 30 days
    private static long minLicense = 1000 * 3600 * 24 * 3;  // ~ roughly 3 days

    long lMax = System.currentTimeMillis() + maxLicense;
    long lMin = System.currentTimeMillis() + minLicense;
    if ((lValidityTimestamp > lMin) && (lValidityTimestamp < lMax)) {
        validityTimestamp = Long.toString(lMax);
    }

    // <--- added by me

    mValidityTimestamp = lValidityTimestamp;
    mPreferences.putString(PREF_VALIDITY_TIMESTAMP, validityTimestamp);
}

Just my two cents, you can define a period of time you would like to check (lets say 3 days). Check for the license after 3 days, if there is no internet, continue letting the user use it for lets say another week max or else the app will not be full functioned. Or just keep it full functioned until there is a connection again, then you can check and reset your time stamp. The license checker will only check when you tell it to.

I can clarify if need be!

Good luck