TL;DR: According to the documentation there are two different ways to purchase a product, which do I use? Do I use an intent or IABHelper.launchPurchaseFlow()
?
According to this documentation, use launchPurchaseFlow();
and attached listener to make a purchase:
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
//Item bought...? Why should I use this option
}
};
mHelper.launchPurchaseFlow(this, SKU_GAS, 10001,
mPurchaseFinishedListener, "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
However, according to this documentation, I must use intents and onActivityForResult()
to purchase a product:
startIntentSenderForResult(pendingIntent.getIntentSender(),
1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
if (resultCode == RESULT_OK) {
//Item bought...? Why should I use this option
}
}
}
Which method should I use to purchase the product? Both options seem extremely similar, but what is the difference, and is one better?
It doesn't matter. If I do use the listener however, IabHelper's launchPurchaseFlow() uses startIntentSenderForResult anyway which calls onActivityResult() when it's finished. So even if I use the listener, I need the onActivityForResult, which they don't mention in the documentation. This link clears that up a bit:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.