如果您正在使用IabHelper类。前往startSetup方法IabHelper .java。添加以下代码
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
serviceIntent.setPackage("com.android.vending");
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."));
}
}
此方法将帮助您将隐式意图转化为显式形式。灵感来自SO回答:https://stackoverflow.com/a/26318757/1446466 bindServiceConn()方法正在创建一个服务。
* @param context
* @param implicitIntent - The original implicit intent
* @return Explicit Intent created from the implicit original intent
*/
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
// Retrieve all services that can match the given intent
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;
}
// Get component info and create ComponentName
ResolveInfo serviceInfo = resolveInfo.get(0);
String packageName = serviceInfo.serviceInfo.packageName;
String className = serviceInfo.serviceInfo.name;
ComponentName component = new ComponentName(packageName, className);
// Create a new intent. Use the old one for extras and such reuse
Intent explicitIntent = new Intent(implicitIntent);
// Set the component to be explicit
explicitIntent.setComponent(component);
return explicitIntent;
}
protected void bindServiceConn() {
//call this method
Intent intent = createExplicitFromImplicitIntent(context.getApplicationContext(), new Intent("com.android.vending.billing.InAppBillingService.BIND"));
context.bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);
}
protected void unbindServiceConn() {
context.unbindService(mServiceConn);
context=null;
}
在原文中,我们已经看到了对'serviceIntent.setPackage(“com.android.vending”);'的调用。我也看到这个错误,并且我有'queryIntentServices'检查以及显式的'setPackage()'调用。奇怪的是,错误消息提到了以'BINL'而不是'BIND'结尾的意图。我看到这个以及原来的海报。 – Carmen