Android licencing ServerManagedPolicy returns dontAllow when no data connection is active
I've implemented the android licensing in my application following the example code using 开发者_JAVA百科the ServerManagedPolicy.
The licence checker works fine, however when a device or emulator has no data connection then the licensing code will always return dontAllow(), while I want it to allow. I cannot seem to find anything on the page above that details how to avoid this.
This is an issue with using test accounts, they will expire the cached result after 1 minute (the minimum)
This is probably because you can change the response the server gives to the test all possibilities and you wouldn't want to wait for cache to expire, or force it to refresh for each case.
- Upload the example app to Market. Make the changes in the profile.
- Wait a few hours, before that you never get the "LICENSED" test result from market
- When testing on the phone, make sure to use the same APK as you uploaded: Use the "
latform-tools/adb install <file>.apk
" command
I can confirm that for releases on the Internal Test track in the Play Store the validityTimestamp does indeed get set to one minute after a successful "allow" response from the server. And on further research, I know where that one-minute caching period comes from. It is not explicitly set by the server. It is actually in the lvl-library code, which is editable as mentioned above. Normally (for production releases) the server returns the validityTimestamp to the ServerManagedPolicy class in the "extras" as follows:
setValidityTimestamp(extras.get("VT"));
and here is the relevant part of what happens in that method:
private void setValidityTimestamp(String validityTimestamp) {
Long lValidityTimestamp;
try {
lValidityTimestamp = Long.parseLong(validityTimestamp);
} catch (NumberFormatException e) {
// No response or not parsable, expire in one minute.
lValidityTimestamp = System.currentTimeMillis() + MILLIS_PER_MINUTE;
}
I added some debugging code to see what the String parameter to this function was. It turns out to be a null String. So the server is returning nothing in the extras map for "VT". The response in the ServerManagedPolicy to such a non-parsable String is to make the validityTimestamp the current time plus one minute (MILLS_PER_MINUTE).
精彩评论