From 065cca2f856e3910c391cc4e2a82b00f38a0c7e8 Mon Sep 17 00:00:00 2001 From: DanDits Date: Fri, 16 Oct 2015 16:51:21 +0200 Subject: [PATCH] Fixed NPE on devices without billing service Especially when testing on emulators the method queryIntentServices() can and will return null, causing the fragment to crash onActivityCreated. --- .../sufficientlysecure/donations/google/util/IabHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Donations/src/main/java/org/sufficientlysecure/donations/google/util/IabHelper.java b/Donations/src/main/java/org/sufficientlysecure/donations/google/util/IabHelper.java index 2ac76fc..a43ddb4 100644 --- a/Donations/src/main/java/org/sufficientlysecure/donations/google/util/IabHelper.java +++ b/Donations/src/main/java/org/sufficientlysecure/donations/google/util/IabHelper.java @@ -265,7 +265,8 @@ public void onServiceConnected(ComponentName name, IBinder service) { Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); - if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { + List queriedIntentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0); + if (queriedIntentServices != null && !queriedIntentServices.isEmpty()) { // service available to handle that Intent mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); }