[Android] Fix NullPointerException on Android 4.4

Nicolas Pomepuy git at videolan.org
Tue Oct 6 10:58:47 CEST 2020


vlc-android | branch: 3.3.x | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Oct  6 09:36:02 2020 +0200| [5636e50ad4802d22ba961dde24308dd4d35e2c69] | committer: Nicolas Pomepuy

Fix NullPointerException on Android 4.4

(cherry picked from commit 654ceb6107e26841b496002e0daecb184236680b)

> https://code.videolan.org/videolan/vlc-android/commit/5636e50ad4802d22ba961dde24308dd4d35e2c69
---

 .../src/main/java/org/videolan/vlc/donations/util/IabHelper.kt    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.kt b/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.kt
index 0a616fc22..0ab93dc7b 100644
--- a/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.kt
+++ b/application/donations/src/main/java/org/videolan/vlc/donations/util/IabHelper.kt
@@ -197,14 +197,14 @@ class IabHelper(ctx: Context, base64PublicKey: String?) {
         }
         val serviceIntent = Intent("com.android.vending.billing.InAppBillingService.BIND")
         serviceIntent.setPackage("com.android.vending")
-        if (mContext!!.packageManager.queryIntentServices(serviceIntent, 0).isNotEmpty()) {
-            // service available to handle that Intent
-            mContext!!.bindService(serviceIntent, mServiceConn!!, Context.BIND_AUTO_CREATE)
-        } else {
+        if (mContext!!.packageManager.queryIntentServices(serviceIntent, 0).isNullOrEmpty()) {
             // no service available to handle that Intent
             listener.invoke(
                     IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                             "Billing service unavailable on device."))
+        } else {
+            // service available to handle that Intent
+            mContext!!.bindService(serviceIntent, mServiceConn!!, Context.BIND_AUTO_CREATE)
         }
     }
 



More information about the Android mailing list