2015-01-12 33 views
4

我得到了一些5.0設備上的顯式意圖異常,但是我的代碼已經有明確的意圖,如下所示:服務意圖必須是顯式的:意圖{act = com.android.vending.billing.InAppBillingService.BIND}

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

我不認爲'setPackage()'做一個明確的'Intent'。 'setComponent()'或'setClassName()'肯定會。據推測,你可以從你的'queryIntentServices()'調用的輸出中獲得這些調用的信息,就像我在[本例中]一樣(https://github.com/commonsguy/cw-omnibus/blob/v6.3 /Binding/Remote/Client/src/com/commonsware/android/advservice/remotebinding/client/DownloadFragment.java#L66-L93)。現在,我不使用Google的IAP,所以我不知道他們是否有其他具體的建議來爲他們的服務制定明確的「Intent」。 – CommonsWare

+0

@CommonsWare根據IAB文檔http://developer.android.com/google/play/billing/billing_integrate.html#billing-service – tyczj

+0

@tyczj:實際上,它沒有。他們使用術語「明確」,但是作爲一般形容詞,而不是專門「明確的」意圖「」。無可否認,這是一個相當混亂的選擇。此外,如果你看[[意圖]絕對龐大的來源](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/content/Intent .java),'setPackage()'確實與'setComponent()'和'setClassName()'有不同的效果。 – CommonsWare

回答

0

嘗試從官方網站獲取最新的com.android.vending.billing.utils應該能夠解決問題。

http://developer.android.com/training/in-app-billing/preparing-iab-app.html#GetSample

+0

自2014年10月以來SDK上的示例並未更新,它與我上面粘貼的代碼幾乎完全相同。 – casolorz

+0

這是另一個線程,我詳細瞭解了我實現的其他修復程序。 https://stackoverflow.com/questions/28177863/java-lang-nullpointerexception-at-iabhelper-startsetupiabhelper-java266/28177965?noredirect = 1#comment44726861_28177965 – casolorz