Android应用内结算 - queryInventoryAsync返回0结果

时间:2014-12-13 13:35:04

标签: android in-app-purchase google-play-services in-app-billing

我在使用应用内结算流程时遇到了令人沮丧的问题。 我在开发控制台中创建了一个新的应用程序,添加了一个名为" P1"的inapp产品,该产品目前处于活动状态;我已将我的应用程序以alpha版本上传到商店,然后升级为测试版,添加了测试人员帐户,并在使用测试人员帐户签名的设备(平板电脑)上安装了apk,并使用开发帐户进行了安装。

现在,我想查询商店以获取非拥有skus的价格等信息。 这是我的活动

中的代码
private void istantiate() {
     List<String> tmp = new List<String>();
     tmp.add("P1");
     final List<String> skus = tmp;
     mHelper = new IabHelper(mContext, base64EncodedPublicKey);
     // enable debug logging (for a production application, you should set this to false).
     mHelper.enableDebugLogging(true);
     //create listener
     bListener = new BillingListener(mHelper, mContext);

     // Start setup. This is asynchronous and the specified listener will be called once setup completes.
     mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
         public void onIabSetupFinished(IabResult result) {

             if (!result.isSuccess()) {
                 // There was a problem.
                 return;
             }             
             getInventory(skus);
         }
     });         
}

...

private void getInventory(List<String> skuList) {
    // Have we been disposed of in the meantime? If so, quit.
    if (mHelper == null) return;

    // IAB is fully set up. Now, let's get an inventory of stuff we own.
    mHelper.queryInventoryAsync(true, skuList, bListener.mQueryFinishedListener);
}

然后当查询完成时,这段代码被称为:

    IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
   public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

      if (result.isFailure()) {
         // handle error
         return;
       }
      ...

   }
};

但是退回的库存是空的。这是 logcat

     12-13 11:21:36.977: D/IabHelper(6034): Billing service connected.
     12-13 11:21:36.977: D/IabHelper(6034): Checking for in-app billing 3 support.
     12-13 11:21:36.987: D/IabHelper(6034): In-app billing version 3 supported for ***
     12-13 11:21:36.987: D/IabHelper(6034): Subscriptions AVAILABLE.
     12-13 11:21:36.987: D/IabHelper(6034): Starting async operation: refresh inventory
     12-13 11:21:36.987: D/IabHelper(6034): Querying owned items, item type: inapp
     12-13 11:21:36.987: D/IabHelper(6034): Package name: ***
     12-13 11:21:36.987: D/IabHelper(6034): Calling getPurchases with continuation token: null
     12-13 11:21:36.997: D/IabHelper(6034): Owned items response: 0
     12-13 11:21:36.997: D/IabHelper(6034): Continuation token: null
     12-13 11:21:36.997: D/IabHelper(6034): Querying SKU details.
     12-13 11:21:37.097: D/IabHelper(6034): Querying owned items, item type: subs
     12-13 11:21:37.097: D/IabHelper(6034): Package name: ***
     12-13 11:21:37.097: D/IabHelper(6034): Calling getPurchases with continuation token: null
     12-13 11:21:37.097: D/IabHelper(6034): Owned items response: 0
     12-13 11:21:37.097: D/IabHelper(6034): Continuation token: null
     12-13 11:21:37.097: D/IabHelper(6034): Querying SKU details.
     12-13 11:21:37.097: D/IabHelper(6034): Ending async operation: refresh inventory

自我的inapp产品发布以来大约一周,所以这不是时间问题。 我尝试清除应用数据,然后重启设备。

编辑:使用android.test.purchased作为测试图片,一切正常。
编辑2 :SKU是&#34;非托管&#34;

3 个答案:

答案 0 :(得分:6)

我也遇到了这个问题,但是一旦我清除 Google Play 应用程序的应用数据,它就解决了。使用adb:

adb shell pm clear com.android.vending

答案 1 :(得分:1)

我认为这是因为Google Play应用中的缓存。通常,Google Play应用缓存每24小时刷新一次。

如果你想通过命令行清除缓存,

@ poqueque的解决方案是有效的。您还可以在手机上转到应用设置并清除Google Play应用的数据/缓存。执行此操作后,请务必重新登录Google Play帐户。

是否有人知道通过代码或查询购买强制刷新Google Play缓存而不使用缓存来获取最新信息的解决方案?

答案 2 :(得分:0)

&#34;拥有物品响应&#34;报告响应代码,在本例中为BILLING_RESPONSE_RESULT_OK,值为0.

看看IabHelper.queryPurchases代码和IabHelper.getSkuDetails,我建议一个好的起点是使用&#39; inventory.hasDetails(&#34; P1&#34;)&#39;或者&#39; inventory.getSkuDetails(&#34; P1&#34;)&#39;在onQueryInventoryFinished。