关于android:In-App-Billing:无法设置IAB Helper异常
In-App-Billing: Cant set up IAB Helper exception
我正在尝试在 Google Play 中使用静态产品 ID 设置应用内结算和测试。
我在这里关注开发者教程。
当在 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 // enable debug logging (for a production application, you should set this to false). //perform service binding to Google Bill ser and return ny errors with IabResult object and listener mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { if (!result.isSuccess()) { // Have we been disposed of in the meantime? If so, quit. // IAB is fully set up. Now, let's get an inventory of stuff we own. //ILLEGALSTAEEXCEPTION THROWN HERE mHelper.launchPurchaseFlow(this, testProduct, RC_REQUEST,
//when purcajsed add this code }//onCreate // Pass on the activity result to the helper for handling |
这对像我这样第一次处理应用购买的人很有用。
设置调用是异步的,因此必须在调用 launchPurchaseFlow 之前完成。所以我禁用了一个"购买"按钮来进行launchPurchaseFlow调用,一旦设置调用完成,它就会启用。工作正常:
设置通话
//执行服务绑定到 Google Bill ser 并返回带有 IabResult 对象和 listener
的任何错误
mHelper.startSetup(...)
|
如果成功则启用按钮并调用 mHelper.launchPurchaseFlow(...) 方法
此外,当使用 google 提供的测试产品 id 时,您可能会注意到在 launchPurchaseFlow 期间引发了签名异常,尽管交易成功,但随后的结果失败,这显然是 google 知道的一个已知错误