Game Development Reference
In-Depth Information
The onActivityResult() method will be called when the purchasing request is processed by
the in-app billing service. It checks 4 possible results: (1) User canceled; (2) Error; (3) Res-
ult is ok but returned data is invalid; (4) Purchase is successful.
//Called when the purchasing request is processed by the in-app billing service
//Parameters:
// requestCode - the specified request code
// resultCode - returned code
// data - the intent data that contains the purchase response info
@ Override
protected void onActivityResult( int requestCode, int resultCode, Intent data)
{
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super .onActivityResult(requestCode, resultCode, data);
int responseCode = data.getIntExtra(RESPONSE_CODE);
String purchaseData
= data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
//handle purchase here
.............
}
}
Step 5: Implementing the purchase finished listener
The purchase finished listener will check the SKU of the purchased item to make sure it
matches the one specified in the purchase request. In the event of a successful purchase,
the method will consume the purchase by discarding the previous data to allow make new
purchase with the same ID. If the purchase is not consumed, future attempts to purchase
the item will throw complaints. For one-time purchase, such as premium upgrade, it's no
need to consume it.
//Checks the SKU of the purchased item to make sure it matches the one specified
//in the purchase request. If succeeded, the method will consume the purchase
//by discarding the previous data to allow make new purchase with the same ID.
//Otherwise, future attempts to purchase the item will throw complaints.
IabHelper.OnIabPurchaseFinishedListener
mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
Search WWH ::




Custom Search