【问题标题】:In App Purchase restoring not working with alpha test version Android在应用程序购买中恢复不适用于 alpha 测试版 Android
【发布时间】:2014-10-23 05:52:57
【问题描述】:

我已经使用 API 3 实现了应用内购买,为了进行测试,我发布了 apk 作为 alpha 测试版本。 我可以使用我的测试帐户进行购买,它工作正常。但我需要检查恢复功能,但购买状态没有改变,因为 apk 处于 alpha 测试中。

如何在发布前检查恢复功能?请帮助我。

mHelper = new IabHelper(this, base64EncodedPublicKey);

    // enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the specified listener
    // will be called once setup completes.
    Log.d(TAG, "Starting setup.");
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {


        public void onIabSetupFinished(IabResult result) {
            Log.d(TAG, "Setup finished.");

            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                complain("Problem setting up in-app billing: " + result);
                return;
            }

            // 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.
            Log.d(TAG, "Setup successful. Querying inventory.");
            ArrayList<String> skuList = new ArrayList<String> ();
            skuList.add("purchase.test");
            skuList.add("purchase.test2");

            skuArray = new JSONArray(skuList);

            mHelper.queryInventoryAsync(true, skuList, mQueryFinishedListener);
        }
    });
}
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
    {
       if (result.isFailure()) {
           Log.v("Menu", "RESULT FALIURE");
          return;
        }

   Log.v("Menu", "this +" + skuArray);
   Log.v("Menu", "Inventory +" + inventory);
   for(int i = 0; i < skuArray.length(); i++){
       try {
          String SKU = skuArray.getString(i);

          if(inventory.getSkuDetails(SKU) != null){
              Toast.makeText(getApplicationContext(), "SKU = " + SKU+"  ....  "+inventory.hasPurchase(SKU), Toast.LENGTH_LONG).show();
              Log.v("Menu", "SKU = " + SKU+"  ....  "+inventory.hasPurchase(SKU));
              Log.v("Menu", "SKU" + SKU + "= " + inventory.getSkuDetails(SKU).getTitle());



          }else{
              Log.v("Menu", "SKU RETURNED NULL" + SKU); 
          }



     } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }


   }

}

};

【问题讨论】:

    标签: android in-app-purchase restore android-billing


    【解决方案1】:

    您可以在每次打开应用程序时调用 getPurchases() 方法,如果用户已经购买了该商品,此方法将返回您的交易详情。这样您就可以检查恢复功能。请参考以下link

    Bundle ownedItems = mservice.getPurchases(3, getPackageName(), "inapp",null);
    int response = ownedItems.getInt("RESPONSE_CODE");
    if (response == 0) {
        //user has purchased the item
       //do something here
    } else {
      //user not purchased
    }
    

    【讨论】:

    • 购买后我仍然让用户没有购买。我这是因为我检查了 alpha 测试 apk。
    • 您使用的是测试产品 ID 吗?你是在 google play 的应用产品中创建的吗?如果可能,请分享您的代码。我最近致力于应用购买并成功集成到我现有的应用中。
    • 我在 sdk 中使用了相同的应用内示例项目代码。示例项目没有 Service 对象。
    • 嘿,请使用这个例子,它对我来说很好用。 dropbox.com/s/y1en5phqz45hd7x/TestInAppPurchase.zip?dl=0
    • 您也可以参考这个 youtube 视频。它清楚地解释了如何从头开始实现它。 youtube.com/watch?v=-h2ESH71hAI
    猜你喜欢
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多