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

匆匆过客 提交于 2019-12-18 12:37:14

问题


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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/13933632/in-app-billing-v3-bindservice-intent-cant-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!