草庐IT

Android 应用内计费 : Can't start launchPurchaseFlow because launchPurchaseFlow is in progress

coder 2023-06-05 原文

我是第一次实现 In App Billing,我正在使用静态 SKU ID 测试我的第一次购买。

第一次效果很好。我调用了 mHelper.launchPurchaseFlow(...) 并完成了测试购买。我的 Activity 收到了 onActivityResult 回调,我确保使用 mHelper.handleActivityResult(...) 对其进行处理。一切都很棒。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Pass on the activity result to the helper for handling
    log("onActivityResult");
    if (!this.mHelper.handleActivityResult(requestCode, resultCode, data)) {
        log("cleared the launch flow");
        // not handled, so handle it ourselves (here's where you'd
        // perform any handling of activity results not related to in-app
        // billing...
        super.onActivityResult(requestCode, resultCode, data);
    }
}

但是,我想测试下一部分,所以我重新启动了应用程序并尝试购买相同的 SKU(静态 purchased SKU)。

mHelper.launchPurchaseFlow(rootActivity, "android.test.purchased", 10002,   
       new IabHelper.OnIabPurchaseFinishedListener() {

        @Override
        public void onIabPurchaseFinished(IabResult result, Purchase purchaseInfo) {
            if (result.isFailure()) {
                log("purchased failed");
            } else {
                log("purchase succeeded");
            }
        }
    }, "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");

第二次尝试购买商品时,我的 OnIabPurchaseFinishedListener 被调用,我在日志中看到 purchase failed:“应用内结算错误:无法购买项目,错误响应:7:项目已拥有"

这是有道理的,但如果我尝试购买其他商品,我的应用会崩溃并出现以下错误:

java.lang.IllegalStateException: Can't start async operation (launchPurchaseFlow) because another async operation(launchPurchaseFlow) is in progress.

当我尝试购买失败时,onActivityResult 回调不会发生,因此失败的启动流程不会得到处理和清理。所以,当我尝试另一笔购买时,这就是它崩溃的原因,因为它应该仍在最后一次失败的交易中。

我做错了什么?如何确保在失败后清理 launchPurchaseFlow()?

最佳答案

我相信您只需获取应用内计费类的更新代码,就不会再遇到同样的问题了。

据我所知,Google 尚未推出对 SDK 管理器的更改。只需将新类复制/粘贴到您的类中,您就不会再遇到问题了。

在此处查看新的代码更改: https://code.google.com/p/marketbilling/source/detail?r=7ec85a9b619fc5f85023bc8125e7e6b1ab4dd69f&path=/v3/src/com/example/android/trivialdrivesample/MainActivity.java

截至 3 月 15 日更改的类是:IABHelper.java、Inventory.java、SkuDetails.java 和一些 MainActivity.java 文件

关于Android 应用内计费 : Can't start launchPurchaseFlow because launchPurchaseFlow is in progress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628155/

有关Android 应用内计费 : Can't start launchPurchaseFlow because launchPurchaseFlow is in progress的更多相关文章

随机推荐