onPurchaseStateChange没有得到所谓的 [英] onPurchaseStateChange not getting called

查看:159
本文介绍了onPurchaseStateChange没有得到所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样品code为在应用程序的功能有:

The sample code for the in-app feature has:

onPurchaseStateChange(PurchaseState purchaseState, String itemId,
            int quantity, long purchaseTime, String developerPayload)

和它带来的应用程序内购买了所进行的信息(ID,多少等等)。

and it brings information on the in-app purchase that was made (id, how much etc.).

在这里我可以更新我的code,但我没有收到来自计费服务这个回调方法任何回应。有什么错示例应用程序。谁能帮助?

and here I can update my code but I am not getting any response in this callback method from Billing Service. What wrong in sample application. can anyone help ?

先谢谢了。

推荐答案

我不知道是什么问题,为什么有时 @overrided onPurchaseStateChange 在请求活动不叫,但我可以确认 onPurchaseStateChange BillingReceiver BillingService有总是被调用。

I'm not sure what the problem is and why sometimes the @overrided onPurchaseStateChange in the requesting Activity isn't called but I can verify that onPurchaseStateChange in the BillingReceiver and BillingService are always called.

由于某些原因,有时,回调只是不一路到达回调用活动。

For some reason, sometimes, the callback just doesn't arrive all the way back to the calling Activity.

顺便说一句,这个问题似乎当你购买一个管理产品或订阅才会发生。如果你买了一个非托管的产品,回调总是会到来。

By the way, this issue seems to only happen when you purchase a managed product or a subscription. If you buy an unmanaged product, the callback will always arrive.

:一种解决方案可能是(在请求采购活动 - 地下城活动在示例应用程序):

@Override
        public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) {

            if (purchaseState == PurchaseState.PURCHASED) {

                onPurchaseStateChange = true;

                // Do whatever you need to do after purchase here first.

            }
        }

        @Override
        public void onRequestPurchaseResponse(RequestPurchase request, ResponseCode responseCode) {


            if (responseCode == ResponseCode.RESULT_OK) {

                if (!onPurchaseStateChange) {
                    // If onPurchaseStateChange = false, the onPurchaseStateChange callback didn't arrive from the BillingService, so you can perform your after purchase actions here.
                }

            } else if (responseCode == ResponseCode.RESULT_USER_CANCELED) {

            } else {

            }
        }

解决方案#2(似乎是正确的解决方案):
谷歌的样本code包含此方法:

Solution #2 (seems to be the right solution): Google's sample code includes this method:

@Override
    protected void onStop() {
        super.onStop();

        ResponseHandler.unregister(YOUR_PURCHASE_OBSERVER);
    }

这将导致观察者被注销打开Play商店购买活动的第二位。当你回到你的活动(无论是购买或后退按钮后),在onStart 被调用,并重新启动 purchaseObserver 但并不总是与购买信息 - 这会导致 onPurchaseStateChange 来从来没有被称为

This causes the observer to be unregistered the second you open the Play store purchase activity. When you go back to your activity (whether after purchase or back button), the onStart is called and re-starts the purchaseObserver but not always with the purchase information - which causes the onPurchaseStateChange to never be called.

一个解决方案,将是从的onStop除去注销并将其移动到的onDestroy。另一种方案是把它存在,但与持有previously收到信息队列启动它。看这里:<一href=\"http://stackoverflow.com/questions/9590019/android-in-app-billing-when-to-unregister-the-responsehandler\">Android应用内计费。当注销ResponseHandler所?

A solution will be to remove the unregister from onStop and move it to onDestroy. Another solution is to leave it there but start it with a queue that hold previously received details. See here: Android in-app-billing. When to unregister the ResponseHandler?

这篇关于onPurchaseStateChange没有得到所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆