Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview android android

Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview


I had the same problem and explicitly setting the package solved it. Similar to Aleksey's answer, but simpler:

Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");// This is the key line that fixed everything for meintent.setPackage("com.android.vending");getContext().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);


As pointed out in answer below, solutions would be to create explicit intent manually:

private Intent getExplicitIapIntent() {        PackageManager pm = mContext.getPackageManager();        Intent implicitIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");        List<ResolveInfo> resolveInfos = pm.queryIntentServices(implicitIntent, 0);        // Is somebody else trying to intercept our IAP call?        if (resolveInfos == null || resolveInfos.size() != 1) {            return null;        }        ResolveInfo serviceInfo = resolveInfos.get(0);        String packageName = serviceInfo.serviceInfo.packageName;        String className = serviceInfo.serviceInfo.name;        ComponentName component = new ComponentName(packageName, className);        Intent iapIntent = new Intent();        iapIntent.setComponent(component);        return iapIntent;    }

Here is the code in L preview sources for check explicit intent. It's got commented currently, but on Nexus 5 with L preview it still runs and throws exception for implicit intents.


Edit: @alav's answer is much more better and simpler. Just add

intent.setPackage("com.android.vending");

All credits for him. And here is the code in L release sources for check explicit intent.


Found clear solution here:https://code.google.com/p/android-developer-preview/issues/detail?id=1674

In Google Licensing Library (LVL), LicenseChecker.java file, replace "bindService" call with this:

 Intent serviceIntent = new Intent(         new String(Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")));         serviceIntent.setPackage("com.android.vending");     boolean bindResult = mContext             .bindService(               serviceIntent,               this, // ServiceConnection.               Context.BIND_AUTO_CREATE);

AND in the AndroidManifest.xml set:android:minSdkVersion="4"

The "setPackage" requires Android version 4.