Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure service query is not null #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/com/example/android/trivialdrivesample/util/IabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolveInfo> packages;

// Are subscriptions supported?
boolean mSubscriptionsSupported = false;

Expand Down Expand Up @@ -264,9 +267,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()) {
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);
mContext.bindService(serviceIntent, bazaarService, Context.BIND_AUTO_CREATE);
}
}
else {
// no service available to handle that Intent
Expand All @@ -287,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);
}
Expand Down