2

我正在使用应用订阅中的 android 开发一个应用。我正在尝试使用 IabHelper.QueryInventoryFinishedListener 查询我的购买项目。但它总是以失败的结果出现。IabResult 返回失败。我在开发者控制台中添加了应用产品。谁可以帮我这个事?

这是我的一些代码,

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));

        }
};

知道为什么它不起作用吗?提前致谢。

4

1 回答 1

2

要使用应用订阅,我认为您将在您创建的 IabHelper 实例上调用“launchSubscriptionPurchaseFlow()”方法。

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

或者

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

其中 itemType = IabHelper.ITEM_TYPE_SUBS

于 2014-01-10T08:59:09.077 回答