Service Intent 必须是显式的:Intent { act=com.android.vending.billing.InAppBillingService.BIND }

4

我在一些5.0设备上遇到了显式意图异常,但是我的代码已经有了显式意图,看起来像这样:

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    PackageManager pm=mContext.getPackageManager();
    List<ResolveInfo> intentServices = pm.queryIntentServices(serviceIntent, 0);
    if (intentServices != null && !intentServices.isEmpty()){
        //this was replaced per this comment https://dev59.com/z2Ij5IYBdhLWcg3wGRmN#24202135
    //if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
        // service available to handle that Intent
        mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
    } else {
        // no service available to handle that Intent
        if (listener != null) {
            listener.onIabSetupFinished(
                    new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                            "Billing service unavailable on device."));
        }
    }

我遇到的异常是这样的:
Non-fatal Exception: java.lang.IllegalArgumentException
Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }

android.app.ContextImpl.validateServiceIntent (ContextImpl.java:1681)

android.content.ContextWrapper.bindService (ContextWrapper.java:538)

IabHelper.startSetup (IabHelper.java:272)

MyApp.createIABHelper (MyApp.java:256)

MyApp.onCreate (MyApp.java:156)

android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1011)

android.app.ActivityThread.handleBindApplication (ActivityThread.java:4520)

android.app.ActivityThread.access$1500 (ActivityThread.java:144)

android.app.ActivityThread$H.handleMessage (ActivityThread.java:1339)

android.os.Looper.loop (Looper.java:135)

android.app.ActivityThread.main (ActivityThread.java:5223)

java.lang.reflect.Method.invoke (Method.java)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:693)

我不确定我做错了什么,每次搜索都会出现serviceIntent.setPackage("com.android.vending");作为修复方法,但是我的代码已经有了这个。谢谢。

根据IAB文档,@CommonsWare所说的是http://developer.android.com/google/play/billing/billing_integrate.html#billing-service。 - tyczj
@CommonsWare 哦,我明白了,有点误导人。 - tyczj
谢谢你们的帮助,很有趣。我发现其他人基本上声称setPackage()是解决方法,甚至IABHelper的开发人员也将其添加到了最新的示例中,这让我感到有些奇怪。 - casolorz
1
@mntgoat 如果您找到了解决方案,请告诉我们,一直在寻找。 - xDragonZ
我有类似的问题,也许你能帮我吗?- http://stackoverflow.com/questions/31652515/bazariranian-android-market-inappbilling-error-in-android-5-lollipop - Saeid
显示剩余6条评论
1个回答

0

SDK上的示例自2014年10月以来就没有更新过了,而且看起来几乎和我上面粘贴的代码一模一样。 - casolorz
这是另一个帖子,我在其中更详细地介绍了我实施的其余修复措施。https://stackoverflow.com/questions/28177863/java-lang-nullpointerexception-at-iabhelper-startsetupiabhelper-java266/28177965?noredirect=1#comment44726861_28177965 - casolorz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接