android L 出现的问题IllegalArgumentException: Service Intent must be explicit: Intent

转载地址:https://stackoverflow.com/questions/24480069/google-in-app-billing-illegalargumentexception-service-intent-must-be-explicit

现象描述:IllegalArgumentException: Service Intent must be explicit: Intent

 原因:android L 在进行远程服务注册时更改了方法

I was getting the same error from older Google Cloud Messaging setup code. The simplest fix appears to be changing

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

其中"com.android.vending.billing.InAppBillingService.BIND"为Service 在AndroidManifest.xml 的Action值

你可能感兴趣的:(android)