物品未消耗(在应用结算中)

时间:2016-02-28 10:56:25

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

我正在尝试将IAB集成到我的应用程序中。我已成功实施,但我有问题。物品没有被消耗。因此,一旦我进行购买,我就无法再次购买该商品。这是我的代码

public class BtnListener implements View.OnClickListener
{
// On-click event handler for all the buttons
@Override
public void onClick(View view)
{
    switch (view.getId())
    {

        case R.id.TwoSeconds:
            mHelper.launchPurchaseFlow(TimeBoosterActivity.this, ITEM_SKU, 10001,
                    mPurchaseFinishedListener, "2");
            break;
    }
}
} 

@Override
protected void onActivityResult(int requestCode, int resultCode,
                            Intent data)
{
if (!mHelper.handleActivityResult(requestCode,
        resultCode, data)) {
    super.onActivityResult(requestCode, resultCode, data);
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
    = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
                                  Purchase purchase)
{
    if (result.isFailure()) {
        // Handle error
        return;
    }
    else if (purchase.getSku().equals(ITEM_SKU)) {
        consumeItem();
        //buyButton.setEnabled(false);

    }

}
 };

 public void consumeItem()
{
     mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

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

    if (result.isFailure()) {
        Toast.makeText(getApplicationContext(), "Failed to consume item",
                Toast.LENGTH_SHORT).show();
    } else {
        mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
                mConsumeFinishedListener);
    }
}
};

  IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
        public void onConsumeFinished(Purchase purchase,
                                      IabResult result) {

            if (result.isSuccess()) {
                String getSeconds=purchase.getDeveloperPayload();
                SharedPreferences saveTwoSeconds=getSharedPreferences(getSeconds, Context.MODE_PRIVATE);
                //clickButton.setEnabled(true);
            } else {
                // handle error
                Toast.makeText(getApplicationContext(), "Failed to consume item",
                        Toast.LENGTH_SHORT).show();
            }
        }
             };

  @Override
  public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
 }

0 个答案:

没有答案