如果购买成功,请在上下文菜单中启用图库

时间:2017-01-23 21:23:47

标签: java android in-app-purchase

从用户购买成功后,我想启用"用户图库"上下文菜单中的项目。但是,我的代码什么也没做,我会感激一些帮助。谢谢!

这是我的onCreateOptionsMenu方法:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);

    if (purchaseSuccessful = false) {
        menu.findItem(R.id.userGallery).setEnabled(false);
        menu.findItem(R.id.purchase).setEnabled(true);
    } else {
        menu.findItem(R.id.userGallery).setEnabled(true);
        menu.findItem(R.id.purchase).setEnabled(false);
    }
    return true;
}

这就是我设置我的" purchaseSuccessful"布尔值:

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = 
      new IabHelper.OnIabPurchaseFinishedListener() {
            public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
                  if (result.isFailure()) {
                       purchaseSuccessful = false;
                       return;
                  } else if (purchase.getSku().equals(ITEM_SKU)) {
                       consumeItem();
                       purchaseSuccessful = true;
                       invalidateOptionsMenu();
                  }
            }
};

0 个答案:

没有答案