Android In app订阅无效

时间:2013-04-10 06:37:29

标签: android in-app-billing subscription

我正在使用应用订阅在Android中开发一个应用程序。我正在尝试使用IabHelper.QueryInventoryFinishedListener查询我的购买项目。但它总是以失败的结果而来。 IabResult返回失败。我在开发者控制台中添加了app产品。任何人都可以帮我吗?

这是我的一些代码,

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

        }
};

任何想法为什么它不起作用?提前谢谢。

1 个答案:

答案 0 :(得分: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