This is part of the code to implement in-app billing. I have two doubts.
@Override
public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
int quantity, long purchaseTime, String developerPayload) {
if (Consts.DEBUG) {
Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
}
if (developerPayload == null) {
logProductActivity(itemId, purchaseState.toString());
} else {
logProductActivity(itemId, purchaseState + "\n\t" + developerPayload);
}
if (purchaseState == PurchaseState.PURCHASED) {
mOwnedItems.add(itemId);
// At this point I have to put Premium changes
}
}
My questions:
-
At the point where I say “At this point I have to put Premium changes”, how can I assure you that the application has been purchased?
-
I have understood that once the purchase is made, this can take a few hours to take effect. How do I ensure that my application will execute the code that’s in point: “At this point I have to put Premium changes”?
If you reach this block
Then you know the purchase is successful. To my experience, the delay after the purchase is made is never more than a couple of seconds. But the user could close the app before the confirmation.
That is why you should implement
restoreTransactions()as well. Each time your activity opens it checks with the server whether the app has been bought.