【问题标题】:Google IAB helper bindService crashGoogle IAB 帮助程序 bindService 崩溃
【发布时间】:2016-08-20 11:46:13
【问题描述】:

我收到以下异常:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{myapppackage2/myapppackage.ui.MainActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
       at android.app.ActivityThread.access$800(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
       at android.os.Handler.dispatchMessage(Handler.java)
       at android.os.Looper.loop(Looper.java)
       at android.app.ActivityThread.main(ActivityThread.java)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
Caused by java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }
       at android.app.ContextImpl.validateServiceIntent(ContextImpl.java)
       at android.app.ContextImpl.bindServiceCommon(ContextImpl.java)
       at android.app.ContextImpl.bindService(ContextImpl.java)
       at android.content.ContextWrapper.bindService(ContextWrapper.java)
       at com.android.vending.billing.util.IabHelper.doBindService(IabHelper.java:277)
       at com.android.vending.billing.util.IabHelper.startSetup(IabHelper.java:268)
       at myapppackage.feature.FeaturesManager.initBilling(FeaturesManager.java:79)
       at myapppackage.ui.MainActivity.onCreate(MainActivity.java:374)
       at android.app.Activity.performCreate(Activity.java)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
       at android.app.ActivityThread.access$800(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
       at android.os.Handler.dispatchMessage(Handler.java)
       at android.os.Looper.loop(Looper.java)
       at android.app.ActivityThread.main(ActivityThread.java)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

我用谷歌搜索了一下,发现我应该添加serviceIntent.setPackage("com.android.vending");,但问题是我已经有了它:

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
        if (resolveInfos != null && !resolveInfos.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."));
            }
        }

xiaomi mi-4c,android 5.1.1,root。

有什么想法吗?

【问题讨论】:

    标签: android google-play in-app-billing android-billing


    【解决方案1】:

    首先使用

    检查您的设备中是否可以使用 Google 服务
    public static boolean checkPlayServices(Context mContext) {
        GoogleApiAvailability api = GoogleApiAvailability.getInstance();
        int resultCode = api.isGooglePlayServicesAvailable(mContext);
        return resultCode == ConnectionResult.SUCCESS;
    }
    

    然后使用这个。

    try {
        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        mContext.bindService(serviceIntent, SceneSelection.this, Context.BIND_AUTO_CREATE);
        } catch (RuntimeException ignored) {
           if (listener != null) {
              listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                                    "Billing service unavailable on device."));
                }
     }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2014-03-31
    • 1970-01-01
    • 2020-08-17
    • 2016-08-06
    相关资源
    最近更新 更多