gpt4 book ai didi

android - IabHelper 购买FinishedListener

转载 作者:IT老高 更新时间:2023-10-28 22:24:23 25 4
gpt4 key购买 nike

如果我通过标准发送购买意向

String mySku = "android.test.purchased";

mHelper.launchPurchaseFlow(this, mySku, 10001, mPurchaseFinishedListener);

我可以购买该项目,它会存储,我可以查询该项目,这也很好。唯一不起作用的是 PurchaseFinishedListener。我的代码与示例应用程序几乎相同,但它似乎根本没有被调用。

12-12 01:40:47.248: D/IabHelper(23502): Calling getPurchases with continuation token: null
12-12 01:40:50.116: D/IabHelper(23502): Starting async operation: launchPurchaseFlow

这是最后两个被调用的方法,之后当我完成购买时它不会调用purchasefinishedlistener

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new OnIabPurchaseFinishedListener() {

@Override
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: "
+ purchase);
if (result.isFailure()) {
complain("Error purchasing: " + result);
// setWaitScreen(false);
return;
}

if (purchase.getSku().equals(mySku)) {
Log.d(TAG, "mySku is being consumed.");
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
}
Log.d(TAG, "Purchase successful.");
new AsyncQuestionsActivity().doInBackground();
}
};

从日志到最后没有任何效果。有什么我只是想念的东西吗?

最佳答案

我发现了如何解决它。在onActivityResult 中实现handleActivityResult。它需要在听众和已启动的购买流程之间架起一座桥梁。

下面是我使用的代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
+ data);

// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}

关于android - IabHelper 购买FinishedListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13831503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com