From c9e5ef76bb8c284b420f5a3182e35b2b88c669a4 Mon Sep 17 00:00:00 2001 From: I'mTheMr Date: Mon, 1 May 2017 00:17:35 +0430 Subject: [PATCH 1/3] make sure "packages" is not null on sdk 21+ packages will be null if bazaar is not installed and cause a null pointer exception on "isEmpty()" and result is a crash --- .../android/trivialdrivesample/util/IabHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/example/android/trivialdrivesample/util/IabHelper.java b/src/com/example/android/trivialdrivesample/util/IabHelper.java index 3602bcc..2a2a94e 100644 --- a/src/com/example/android/trivialdrivesample/util/IabHelper.java +++ b/src/com/example/android/trivialdrivesample/util/IabHelper.java @@ -264,9 +264,13 @@ public void onServiceConnected(ComponentName name, IBinder service) { Intent serviceIntent = new Intent("ir.cafebazaar.pardakht.InAppBillingService.BIND"); serviceIntent.setPackage("com.farsitel.bazaar"); - if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { + List packages = mContext.getPackageManager().queryIntentServices(serviceIntent, 0); + if (packages !=null) { + // make sure "packages" is not null + if (!(packages.isEmpty())) { // service available to handle that Intent - mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); + bindService(serviceIntent, bazaarService, Context.BIND_AUTO_CREATE); + } } else { // no service available to handle that Intent From c13641ffa9907750f0f62f22284590c9aecfc8e8 Mon Sep 17 00:00:00 2001 From: I'mTheMr Date: Mon, 1 May 2017 00:24:30 +0430 Subject: [PATCH 2/3] Update IabHelper.java --- src/com/example/android/trivialdrivesample/util/IabHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/example/android/trivialdrivesample/util/IabHelper.java b/src/com/example/android/trivialdrivesample/util/IabHelper.java index 2a2a94e..1b6db73 100644 --- a/src/com/example/android/trivialdrivesample/util/IabHelper.java +++ b/src/com/example/android/trivialdrivesample/util/IabHelper.java @@ -269,7 +269,7 @@ public void onServiceConnected(ComponentName name, IBinder service) { // make sure "packages" is not null if (!(packages.isEmpty())) { // service available to handle that Intent - bindService(serviceIntent, bazaarService, Context.BIND_AUTO_CREATE); + mContext.bindService(serviceIntent, bazaarService, Context.BIND_AUTO_CREATE); } } else { From a93a31559f2b8c7f81b5d75643c6ec1f8b5dbd75 Mon Sep 17 00:00:00 2001 From: I'mTheMr Date: Mon, 1 May 2017 00:50:58 +0430 Subject: [PATCH 3/3] service may not be binded service will be binded if the packages is null --- .../android/trivialdrivesample/util/IabHelper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/example/android/trivialdrivesample/util/IabHelper.java b/src/com/example/android/trivialdrivesample/util/IabHelper.java index 1b6db73..6a78acf 100644 --- a/src/com/example/android/trivialdrivesample/util/IabHelper.java +++ b/src/com/example/android/trivialdrivesample/util/IabHelper.java @@ -79,7 +79,10 @@ public class IabHelper { // Has this object been disposed of? (If so, we should ignore callbacks, etc) boolean mDisposed = false; - + + // Bazaar service resolve + List packages; + // Are subscriptions supported? boolean mSubscriptionsSupported = false; @@ -264,7 +267,7 @@ public void onServiceConnected(ComponentName name, IBinder service) { Intent serviceIntent = new Intent("ir.cafebazaar.pardakht.InAppBillingService.BIND"); serviceIntent.setPackage("com.farsitel.bazaar"); - List packages = mContext.getPackageManager().queryIntentServices(serviceIntent, 0); + packages = mContext.getPackageManager().queryIntentServices(serviceIntent, 0); if (packages !=null) { // make sure "packages" is not null if (!(packages.isEmpty())) { @@ -291,7 +294,7 @@ public void onServiceConnected(ComponentName name, IBinder service) { public void dispose() { logDebug("Disposing."); mSetupDone = false; - if (mServiceConn != null) { + if ((mServiceConn != null)&&(packages !=null)) { logDebug("Unbinding from service."); if (mContext != null) mContext.unbindService(mServiceConn); }