android-应用内结算:无法设置IAB Helper异常

android-应用内结算:无法设置IAB Helper异常,第1张

概述我正在尝试使用GooglePlay中的静态产品ID设置应用内结算并进行测试.正在关注开发人员教程here.在labHelper对象上调用launhPurcahseFlow方法时,出现异常:java.lang.IllegalStateException:IABhelperisnotsetup.Can’tperformoperation:launchPurchaseFlowatcom

我正在尝试使用Google Play中的静态产品ID设置应用内结算并进行测试.
正在关注开发人员教程here.
在labHelper对象上调用launhPurcahseFlow方法时,出现异常:

java.lang.IllegalStateException: IAB helper is not set up. Can’t
perform operation: launchPurchaseFlow at
com.androID.vending.billing.IabHelper.checkSetupDone(IabHelper.java:782)

一直在搜索数小时,找不到有效的解决方案.
任何输入表示赞赏.

我的代码是:

protected voID onCreate(Bundle savedInstanceState) {        // Todo auto-generated method stub        super.onCreate(savedInstanceState);           // compute your public key and store it in base64EncodedPublicKey           mHelper = new IabHelper(this, base64EncodedPublicKey);        // enable deBUG logging (for a production application, you should set this to false).            mHelper.enableDeBUGLogging(true);           //perform service binding to Google Bill ser and return ny errors with IabResult object and Listener            mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {                public voID onIabSetupFinished(IabResult result) {                    Log.d(TAG, "Setup finished.");                    if (!result.isSuccess()) {                        // Oh noes, there was a problem.                        alert("Problem setting up in-app billing: " + result);                        return;                    }                    // Have we been disposed of in the meantime? If so, quit.                    if (mHelper == null) return;                    // IAB is fully set up. Now, let's get an inventory of stuff we own.                    Log.d(TAG, "Setup successful. querying inventory.");                    //mHelper.queryInventoryAsync(mGotInventoryListener);                }            });           //ILLEgalSTAEEXCEPTION THROWN HERE           mHelper.launchPurchaseFlow(this, testProduct, RC_REQUEST,                      new IabHelper.OnIabPurchaseFinishedListener() {                       public voID onIabPurchaseFinished(IabResult result, Purchase purchase)                        {                          if (result.isFailure()) {                             Log.d(TAG, "Error purchasing: " + result);                             return;                          }                           else if (purchase.getSku().equals(testProduct)) {                             // give user access to premium content and update the UI                              //set the purchaesd booean to true                            //when purcaJsed add this code                                editor.putBoolean("purchased", true);                                editor.commit();                                Toast.makeText(getApplicationContext(), "ADD FREE VERSION PURCAHSED!!!" +                                        " Details OrderID: "+purchase.getorderID() +" Payload ID: "+purchase.mDeveloperPayload, Toast.LENGTH_LONG).show();                                Log.d("CONNECT TO Google BILL", "ITEM PURCAHSED! : "+purchased);                          }                       }                    }, "diveAppPurchase");    }//onCreate@OverrIDe        protected voID onActivityResult(int requestCode, int resultCode, Intent data) {            Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);            if (mHelper == null) return;            // 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.");            }        }

解决方法:

这对于像我这样第一次进行应用程序购买的人很有用.

设置调用是异步的,因此必须在调用launchPurchaseFlow之前完成.因此,我禁用了“购买”按钮以进行launchPurchaseFlow调用,设置调用完成后将启用该按钮.工作正常:

设定通话
           //将服务绑定到Google Bill ser,并使用IabResult对象和侦听器返回ny错误

        mHelper.startSetup(...)

如果成功,则启用按钮并调用mHelper.launchPurchaseFlow(…)方法

另外,当使用Google提供的测试产品ID时,您可能会注意到在launchPurchaseFlow期间抛出了签名异常,但随后的结果失败,尽管交易成功,但这显然是Google已知的已知错误.

总结

以上是内存溢出为你收集整理的android-应用内结算:无法设置IAB Helper异常全部内容,希望文章能够帮你解决android-应用内结算:无法设置IAB Helper异常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1078331.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存