Reputation: 7782
I am trying to solve the "Already Brought" error by querying for previously owned item then consuming them, my problem is I don't know how to get the "Purchase" object after I query for brought inventory:
I invoke the query here:
List<String> st = new ArrayList<String>();
st.add(AdRemovalSKU);
mHelper.queryInventoryAsync(true,st,mGotInventoryListener);
This is my listener implementation:
mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (mHelper == null) return;
if (result.isFailure()) {
return;
}
if(inventory.hasPurchase(AdRemovalSKU)) {
mHelper.consumeAsync(purchase, context);
}
}
};
I want to call consumeAsync, but where do I get the "purchase" variable?
Upvotes: 1
Views: 553
Reputation: 798
You can Check the following.
mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (mHelper == null) return;
if (result.isFailure()) {
return;
}
Purchase purchased = inventory.getPurchase(AdRemovalSKU);
if(purchased!=null){
//Your purchase details will be in the purchased object.
//You can also do the developer payload verification.
}
}
};
If the above code alone is not working, then you need to change following also.
mHelper.queryInventoryAsync(true,st,mGotInventoryListener);
To
mHelper.queryInventoryAsync(mGotInventoryListener);
Upvotes: 1
Reputation: 7782
Figure it out, just use
inventory.getPurchase(AdRemovalSKU)
and it will return the purchase.
Upvotes: 0