diff --git a/src/com/example/android/trivialdrivesample/util/IabHelper.java b/src/com/example/android/trivialdrivesample/util/IabHelper.java index 3602bcc..a3d6249 100644 --- a/src/com/example/android/trivialdrivesample/util/IabHelper.java +++ b/src/com/example/android/trivialdrivesample/util/IabHelper.java @@ -22,6 +22,8 @@ import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.ServiceConnection; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -218,7 +220,12 @@ public void onServiceDisconnected(ComponentName name) { public void onServiceConnected(ComponentName name, IBinder service) { if (mDisposed) return; logDebug("Billing service connected."); - mService = IInAppBillingService.Stub.asInterface(service); + if (!"com.farsitel.bazaar".equals(name.getPackageName())) { + logDebug("can't find bazaar app!"); + return; + } else { + mService = IInAppBillingService.Stub.asInterface(service); + } String packageName = mContext.getPackageName(); try { logDebug("Checking for in-app billing 3 support."); @@ -264,7 +271,9 @@ 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()) { + PackageManager pm=mContext.getPackageManager(); + List intentServices = pm.queryIntentServices(serviceIntent, 0); + if (intentServices != null && !intentServices.isEmpty()) { // service available to handle that Intent mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE); } @@ -287,7 +296,7 @@ public void onServiceConnected(ComponentName name, IBinder service) { public void dispose() { logDebug("Disposing."); mSetupDone = false; - if (mServiceConn != null) { + if (mServiceConn != null && mService!=null) { logDebug("Unbinding from service."); if (mContext != null) mContext.unbindService(mServiceConn); }