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

▼魔方 西西 提交于 2019-12-05 22:24:37

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()
        }
    });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!