2013-04-10 53 views
2

我正在開發一個應用程序在android應用程序訂閱使用。我試圖用IabHelper.QueryInventoryFinishedListener查詢我的購買物品。但它始終是失敗的結果。 IabResult返回失敗。我在開發者控制檯中添加了應用產品。誰可以幫我這個事?Android在應用程序訂閱不工作

這裏是我的一些代碼,

bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), 
         mServiceConn, Context.BIND_AUTO_CREATE); 

String base64EncodedPublicKey = "my key";           

mHelper = new IabHelper(this, base64EncodedPublicKey); 
     mHelper.enableDebugLogging(true); 
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 
       public void onIabSetupFinished(IabResult result) { 
        if (!result.isSuccess()) { 
         System.out.println("Not Success");      
        Log.d("In APP Billing", "Problem setting up In-app Billing: " + result); 
        return; 
        } else { 
         System.out.println("Success"); 
         Log.d(" In APP Billing", "Setting up In-app Billing Success: " + result); 
        } 

        List<String> additionalSkuList = new ArrayList<String>(); 
        additionalSkuList.add(SKU_ID);     

        mHelper.queryInventoryAsync(true, additionalSkuList, 
          mQueryFinishedListener); 

       } 


});  

    IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() { 

     @Override 
     public void onQueryInventoryFinished(IabResult result, Inventory inv) { 
      // TODO Auto-generated method stub 

      if (result.isFailure()) { 
       // handle error 
       System.out.println("mQueryFinishedListener is Failure"); // i am always getting this 
       return; 
      } 
      System.out.println("mQueryFinishedListener is Success"); 


      Boolean hasPur = inv.hasPurchase(SKU_ID); 

      if (hasPur) { 
       System.out.println("Query - - subscribed "); 
       isSubscribed = true; 
      } else { 
       System.out.println("Query - not subscribed "); 
       isSubscribed = false; 
      } 

      System.out.println("Purchase panic:"+inv.getPurchase(SKU_ID)); 

     } 
}; 

任何想法,爲什麼它不工作?提前致謝。

+0

對不起,我驗證了我的答案,想通這是錯誤的。你在測試你的代碼的什麼設備?您確定設備上的Google Play支持IAB V3(大約半年前推出)嗎? – 2013-04-10 06:48:38

+0

我正在使用galaxy y。它在2天前工作。我現在改變了一些編碼。但我不知道這一點。由於某些原因,它不工作。 – Amarnath 2013-04-10 06:58:12

+0

哪一個電話正在失敗?你會得到哪些狀態碼? – 2013-04-10 06:59:59

回答

2

要在應用程序訂閱中工作,我認爲您將在您創建的IabHelper實例上調用「launchSubscriptionPurchaseFlow()」方法。

mHelper.launchSubscriptionPurchaseFlow(Activity act, String sku, int requestCode, 
     OnIabPurchaseFinishedListener listener, String extraData); 

OR

mHelper.launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode, 
       OnIabPurchaseFinishedListener listener, String extraData); 

其中ITEMTYPE = IabHelper.ITEM_TYPE_SUBS