Android 计费异常

标签 android android-billing

我正在测试我的帐单,但遇到了这个异常:

java.lang.IllegalStateException: Can't start async operation (launchPurchaseFlow) because another async operation(launchPurchaseFlow) is in progress.
        at utils.IabHelper.flagStartAsync(IabHelper.java:711)
        at utils.IabHelper.launchPurchaseFlow(IabHelper.java:316)
        at utils.IabHelper.launchPurchaseFlow(IabHelper.java:294)
        at com.problemio.SubscribeIntroActivity$6.onClick(SubscribeIntroActivity.java:117)
        at android.view.View.performClick(View.java:2532)
        at android.view.View$PerformClick.run(View.java:9308)
        at android.os.Handler.handleCallback(Handler.java:587)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:150)
        at android.app.ActivityThread.main(ActivityThread.java:4293)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)

在我运行这段代码之后:

    Button subscribe = (Button)findViewById(R.id.subscribe);
    subscribe.setOnClickListener(new Button.OnClickListener() 
    {  
       public void onClick(View v) 
       {              
           // FIRST CHECK IF THE USER IS ALREADY A SUBSCRIBER.
          mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);

       }
    });   

但在此之前,我以测试用户身份运行它,测试产品 id 是:android.test.purchased,它可以工作。但是当我将产品 ID 更改为我自己的产品 ID 时,它崩溃了,但出现了上述异常。

知道为什么会这样吗? 谢谢!

最佳答案

IabHelper 一次只允许执行一个异步查询。你需要实现onActivityResult()并将参数传递到IabHelper的handleActivityResult()方法中。

应用内计费示例代码实现方法如下:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);

    // Pass on the activity result to the helper for handling
    if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
        // 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);
    }
    else {
        Log.d(TAG, "onActivityResult handled by IABUtil.");
    }
}

关于Android 计费异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14130044/

相关文章:

android - 捕获用户输入并使用按钮将其直接发送到电子邮件地址

java - 如何在我的自定义 osmdroid map 上设置拖动开始和结束监听器?

Android 应用内结算 "Un-purchase"用于测试?

android - 是否可以在我的免费 Android 应用中添加应用内付费功能?

android - 什么是com.android.vending.BILLING,如何使用?

android - jetpack compose 中的图层列表相当于什么?

Android:如何加载 KML

java - TabLayout viewpager switch Tab2 only editext在Tab1上有效

android - 使用 SOOMLA Android Store 计费包装器请求交易

Android 计费 v3 - BillingClientImpl.java 中的 NullPointerException :668