Android LicenseChecker因空指针异常而崩溃 [英] Android LicenseChecker crashes with null pointer exception
问题描述
如果没有将Android手机登录到Google Play,似乎checkAccess调用将引发NullPointerException并最终导致应用程序崩溃:
It seems that if an Android phone is not logged in to Google Play, a checkAccess-call will throw a NullPointerException and eventually crash the application:
// user not logged in to Google Play
LicenseChecker licenseChecker = new LicenseChecker(...);
licenseChecker.checkAccess(...) // throws a nullpointer exception and crasches the app
NullPointerException发生在Android框架内部的单独线程中:
The NullPointerException happens deep inside the Android framework in a separate thread:
FATAL EXCEPTION: background thread
java.lang.NullPointerException
com.google.android.vending.licensing.LicenseValidator.verify()
因此,应用程序似乎无法捕获它并避免崩溃。
hence there seems no way for the application to catch it and avoid the crash.
任何想法如何避免此崩溃? (应该是合法的情况,不要登录Google Play)
Any ideas how to avoid this crash? (t should be a legal situation not to be logged into Google Play)
我唯一想到的方法是在调用checkAccess之前检查Google Play登录状态。
The only way I can think of is to check Google Play login status prior to invoking checkAccess.
推荐答案
我修改了方法LicenseValidator.verify(),并在开头添加了保护检查:
I modified the method LicenseValidator.verify(), adding a protection check at the begining:
public void verify(PublicKey publicKey, int responseCode, String signedData, String signature) {
if (signedData==null){
handleInvalidResponse();
return;
}
...
}
这篇关于Android LicenseChecker因空指针异常而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!