Game Development Reference
In-Depth Information
billing system to make sure that the purchase has been made by calling the
queryInvent-
oryAsync()
method of the
mHelper
object.
Next, the
mConsumeFinishedListener
listener is designed to receive the notification when
the consumption operation has completed and then handle the consumption response from
Google Play.
//Queries the billing system to make sure that the purchase has been made
public void
consumePurchasedItem() {
mHelper.queryInventoryAsync(
mReceivedInventoryListener
);
}
//Consumes the item via a call to the consumeAsync() method of the mHelper object
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
=
new
IabHelper.QueryInventoryFinishedListener() {
public void
onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if
(result.isFailure()) {
// Handles failure
}
else
{
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
}
}
};
//Handles the consumption response from Google Play
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener
=
new
IabHelper.OnConsumeFinishedListener() {
public void
onConsumeFinished(Purchase purchase,IabResult result){
if
(result.isSuccess()) {
// Handles success
//provision the in-app purchase to the user
// (for ex, credit 50 gold coins to player's character)
}
else
{
// handles error
}
}
};
Search WWH ::
Custom Search