我在某些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 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."));
}
}
我得到的例外是:
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");
作为修复,但我的代码已经有了。
感谢。
答案 0 :(得分:0)
尝试从官方网站获取最新的 com.android.vending.billing.utils ,应该可以解决问题。
http://developer.android.com/training/in-app-billing/preparing-iab-app.html#GetSample