Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-App Billing v3, bindService() Intent can't be found

I am using in-app billing from Google for Android for the first time. However, if a user doesn't have an internet connection or no google framework installed (e.g. with custom roms) and probably other occasions (like wrong/old market version etc.) This method (inside the provided IabHelper class):

        mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
                         mServiceConn, Context.BIND_AUTO_CREATE);

Doesn't work and no service get's established. With a small debugging information from "Activity Manager":

12-17 19:58:31.184: W/ActivityManager(76): Unable to start service Intent { act=com.android.vending.billing.InAppBillingService.BIND }: not found

Has anyone found any way to "catch" this error in a meaningful way, or any workaround to check if the Intent/Package is available?

Thanks in advance.

like image 710
Aeefire Avatar asked Dec 18 '12 13:12

Aeefire


1 Answers

argh, found answer myself shortly after:

You have to check if the intent receiver is available by implementing a method like suggested here: [can i use this intent - blogpost][1]

(edit) However, this method needs some serious changes to be applicable for the billing-service, as the original method only checks for default intents, which is not what we want.

however, my implementation looks like the following and seems to work, at least on those devices, specifications etc. i tested: (ONLY TESTED FOR V3 OF IN APP BILLING)

public static boolean isBillingAvailable(Context context) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    List<ResolveInfo> list = packageManager.queryIntentServices(intent, 0);
    return list.size() > 0;
}
like image 104
Aeefire Avatar answered Oct 30 '22 21:10

Aeefire