2015-07-21 129 views
3

繼開發人員網站上的文檔後,我最近在我的應用程序中實施了InAppBilling v3。我已經使用TRIVIAL DRIVE示例中提供的utils包中的類。InAppBilling v3 IabResult響應代碼BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED

我現在面臨的問題是,如果一個用戶在應用內產品的購買已經在開展purchse另一臺設備上再次流動Play商店對話框顯示項目已擁有IabResult返回的響應碼不匹配到常量IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED。返回的響應代碼實際上是IabHelper類中的錯誤代碼之一(-1005用戶取消)。

我真的很想知道如何得到實際的響應代碼而不是錯誤代碼。任何幫助,將不勝感激。

下面是回調代碼

// Callback for when a purchase is finished 
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = 
     new IabHelper.OnIabPurchaseFinishedListener() { 
      public void onIabPurchaseFinished(IabResult result, Purchase purchase) { 

       if (result.isFailure()) { 
        if (result.getResponse() == 
          IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) { 
         //already owned 
         boolean isPremium = true; 
         SharedPrefsUtils.setPremium(BaseActivity.this, isPremium); 
         EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium)); 
         //setWaitScreen(false); 
         return; 
        } 
        //handle error 
        complain(result.getResponse() + " " + "Error purchasing: " + result); 
        //setWaitScreen(false); 
        return; 
       } 
       if (!verifyDeveloperPayload(purchase)) { 
        //corrupted 
        complain("Error purchasing. Authenticity verification failed."); 
        //setWaitScreen(false); 
        return; 
       } 

       //successful 
       if (purchase.getSku().equals(NO_ADS_PRODUCT_ID)) { 
        // bought the premium upgrade! 
        alert("Thank you for upgrading to premium!"); 
        boolean isPremium = true; 
        SharedPrefsUtils.setPremium(BaseActivity.this, isPremium); 
        EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium)); 
        //setWaitScreen(false); 
       } 
      } 
     }; 

回答

4

我終於設法找到在IabHelper代碼的問題,所以在這裏不言而喻每當Activity.RESULT_CANCELED結果代碼在handleActivityResult返回方法IabResult對於所有這些情況下固定與用戶取消(-1005)無論原因是什麼。因此,爲了得到正確的實際響應代碼替換下面的代碼handleActivityResult

else if (resultCode == Activity.RESULT_CANCELED) { 
     logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode)); 
     result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled."); 
     if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); 
    } 

與此

else if (resultCode == Activity.RESULT_CANCELED) { 
     logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode)); 
     result = new IabResult(responseCode, null); 
     if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null); 
    } 

希望它會節省時間某人