我在一些5.0设备上遇到了显式意图异常,但是我的代码已经有了显式意图,看起来像这样:
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 https://dev59.com/z2Ij5IYBdhLWcg3wGRmN#24202135
//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."));
}
}
我遇到的异常是这样的:
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)
我不确定我做错了什么,每次搜索都会出现
serviceIntent.setPackage("com.android.vending");
作为修复方法,但是我的代码已经有了这个。谢谢。
setPackage()
是解决方法,甚至IABHelper的开发人员也将其添加到了最新的示例中,这让我感到有些奇怪。 - casolorz