If you reach this block
if (purchaseState == PurchaseState.PURCHASED) {
...
}
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.
/**
* A {@link PurchaseObserver} is used to get callbacks when Android Market sends
* messages to this application so that we can update the UI.
*/
private class MyPurchaseObserver extends PurchaseObserver {
public DownloaderPurchaseObserver(Handler handler) {
super(home, handler);
}
@Override
public void onBillingSupported(boolean supported) {
...
yourBillingService.restoreTransactions();
...
}
@Override
public void onRestoreTransactionsResponse(RestoreTransactions request,
ResponseCode responseCode) {
if (responseCode == ResponseCode.RESULT_OK) {
// repeat your premium validation here
} else {
if (Consts.DEBUG) {
Log.e(TAG, "RestoreTransactions error: " + responseCode);
}
}
}
}