开发者

Android LVL (Licensing service) is incredibly slow! -- solutions? Async?

开发者 https://www.devze.com 2023-03-29 08:28 出处:网络
I looked around online and saw some other posts complaining about how the Android licensing (LVL) library is slow, but no solutions.On an HTC Thunderbolt (brand new phone) it delays the startup time o

I looked around online and saw some other posts complaining about how the Android licensing (LVL) library is slow, but no solutions. On an HTC Thunderbolt (brand new phone) it delays the startup time of a test app by 3-5+ seconds.

Does anyone have any开发者_运维技巧 experience or ideas on calling this library asynchronously? Other solutions? I am just using the sample code provided basically. The really annoying part is that the whole app is frozen while this simple license check occurs, it's really bad.

Thanks!


Nitwit figured it out: the licenseCheck is asynchronous.

So just fire it, then open the app with your next few lines of code, and when the response arrives, that will interrupt the app (i.e. if you set up for there to be a dialog if the license is not valid, then your app will start to load and then the dialog appears and this blocks everything).

Make sure to include finish() in the follow-up of all code that follows on a "don't allow" situation.

Great results: the app loses four or five seconds in load time.


I might be wrong but I have the feeling that the LVL server is very slow and buggy when used in debug mode, that is to say when I install the app on my device directly with Android Studio and test the LVL implementation by changing the response in the Google Play Console. Indeed, it is in this case the sandbox servers which are used, not the Google Play production servers.

So, to have quick and proper responses for the LVL implementation, I upload a test apk (with toasts to see the LVL responses) to the Google Play Console in beta test channel. Then, I download the apk from Google Play thanks to the Google Play beta test URL. The LVL responses are much faster and reliable.

Please tell me if you confirm this observation.


Implement LicenseCheckerCallback in your Activity and call it like this:

mLicenseChecker = new LicenseChecker(this, new MyPolicy(this, new AESObfuscator(getSalt(), getPackageName(), getDeviceId())), PUBLIC_KEY);
mLicenseChecker.checkAccess(new MyCheckerCallback());
mHandler = new Handler();

Then post to the handler if the license is invalid: In MyCheckerCallback:

public void dontAllow() {
    if (isFinishing()) {
        return; //don't update UI when app is finishing
    }
    mHandler.post(new Runnable() {
    public void run() {
        //show toast message stating license is invalid
        //redirect user to Market
        //call finish()
        }
    });
}
0

精彩评论

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