4

I am getting the explicit intent exception on some 5.0 devices however my code already has the explicit intent and looks like this:

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 http://stackoverflow.com/a/24202135/704836
    //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."));
        }
    }

The exception I am getting is this:

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)

I'm not sure what I am doing wrong, every search I make comes up with serviceIntent.setPackage("com.android.vending"); as the fix but my code already has that.

Thanks.

casolorz
  • 8,486
  • 19
  • 93
  • 200
  • I do not think that `setPackage()` makes an explicit `Intent`. `setComponent()` or `setClassName()` definitely would. Presumably, you would get the information for those calls from the output of your `queryIntentServices()` call, as I did [in this sample](https://github.com/commonsguy/cw-omnibus/blob/v6.3/Binding/Remote/Client/src/com/commonsware/android/advservice/remotebinding/client/DownloadFragment.java#L66-L93). Now, I don't use Google's IAP, so I do not know if they have other specific advice for crafting the explicit `Intent` for their service. – CommonsWare Jan 12 '15 at 21:29
  • @CommonsWare according to the IAB documentation it does http://developer.android.com/google/play/billing/billing_integrate.html#billing-service – tyczj Jan 12 '15 at 21:31
  • @tyczj: Actually, it doesn't. They use the term "explicitly", but as a general adjective, not specifically "explicit `Intent`". Admittedly, that's a rather confusing choice of words on their part. Moreover, if you look at [the absolutely gargantuan source to `Intent`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/content/Intent.java), `setPackage()` definitely has different effects than do `setComponent()` and `setClassName()`. – CommonsWare Jan 12 '15 at 21:32
  • @CommonsWare ah I see, kind of deceiving – tyczj Jan 12 '15 at 21:34
  • Interesting, thank you both for the help. I do find it odd that other people are basically claiming the `setPackage()` is the fix and even the IABHelper people added it to the latest sample. – casolorz Jan 13 '15 at 03:26
  • 1
    @mntgoat Let us know if you manage to find a solution for this, been looking it. – xDragonZ Jan 14 '15 at 04:11
  • @mntgoat any update on this? I'm having the same issue and so far couldn't find a solution. Part of the problem is that I can reproduce the problem locally. – Ricardo Feb 12 '15 at 09:10
  • I ended up using code from another stackoverflow post that got the explicit intent, that led to a different error, however that error is mostly only happening with rooted devices so it wouldn't surprise me if they are trying to cheat in-app purchases. Here is the other post I made about it https://stackoverflow.com/questions/28177863/java-lang-nullpointerexception-at-iabhelper-startsetupiabhelper-java266/28177965?noredirect=1#comment44726861_28177965 – casolorz Feb 12 '15 at 19:13
  • i have similar problem , maybe help me? - http://stackoverflow.com/questions/31652515/bazariranian-android-market-inappbilling-error-in-android-5-lollipop – Saeid Aug 02 '15 at 07:08
  • possible duplicate of [Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview](http://stackoverflow.com/questions/24480069/google-in-app-billing-illegalargumentexception-service-intent-must-be-explicit) – rds Aug 14 '15 at 18:47
  • I don't think so, that question says the solution is to add `intent.setPackage("com.android.vending");` but my code already has that unless I'm reading the answer wrong. – casolorz Aug 14 '15 at 18:55

1 Answers1

0

Try to get the latest com.android.vending.billing.utils from official site, should be able to fix the problem.

http://developer.android.com/training/in-app-billing/preparing-iab-app.html#GetSample

Cadrick Loh
  • 721
  • 1
  • 7
  • 19
  • The sample on the SDK has not been updated since October 2014 and it looks almost identical to the code I have pasted above. – casolorz Mar 09 '15 at 14:31
  • Here is another thread where I went into more details about the rest of the fix I implemented. https://stackoverflow.com/questions/28177863/java-lang-nullpointerexception-at-iabhelper-startsetupiabhelper-java266/28177965?noredirect=1#comment44726861_28177965 – casolorz Mar 09 '15 at 14:32