【问题标题】:Android IAP: Handle already buyed itemsAndroid IAP:处理已购买的商品
【发布时间】:2014-09-13 08:04:34
【问题描述】:

我正在尝试在应用购买中使用 Android。我正在使用官方文档和 util(Base64 等)。我正在使用托管项。 我可以在哪里以及如何处理已经购买的物品? (我将布尔值设置为 true 并将其保存到 sharedpreferences,但如果我删除并安装应用程序,sharedpreferences 将丢失。)

现在,如果我单击“购买按钮”,我会收到“错误 7:项目已拥有”。 购买的商品类似于我的应用的专业版。

问题: 我可以在哪里以及如何处理已经购买的物品?

【问题讨论】:

    标签: android error-handling in-app-purchase


    【解决方案1】:

    您好,在您显示在应用购买屏幕之前,您应该检查您之前是否已经订购过非消耗品。

    不错的文章:

    http://developer.android.com/training/in-app-billing/purchase-iab-products.html

    如何调用方法:

    mHelper = new IabHelper(this, base64EncodedPublicKey);
    
    mHelper.enableDebugLogging(true);
    
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
    
    if (!result.isSuccess()) {
    return;
    }
    
    if (mHelper == null) return;
    List<String> st = new ArrayList<String>();
    st.add(ITEM_SKU);
    mHelper.queryInventoryAsync(true,st,mGotInventoryListener);
    }
    });
    

    如何查询物品的库存。

    IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
    
    if (mHelper == null) return;
    
    if (result.isFailure()) {
    return;
    }
    
    if(inventory.hasPurchase(ITEM_SKU)) {
    Intent intent = null;
    intent = new Intent(getActivity(), Ce.class); 
    startActivity(intent);
    }
    }
    };
    

    【讨论】:

      猜你喜欢
      • 2018-05-25
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 2016-05-28
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      相关资源
      最近更新 更多