android-来自Google Play的应用内结算广播顺序错误? (静态测试)
作者:互联网
应用内结算的Android文档在以下方面似乎很清楚.在REQUEST_PURCHASE之后,您将显示具有未决意图的结帐(很好,没有问题),然后用户与结帐进行交互并按下“购买”按钮(在这种情况下,我使用的是静态商品ID android.test.purchased).
现在,我的广播接收器应该收到RESPONSE_CODE,然后收到IN_APP_NOTIFY.嗯,那没有发生.有时我会首先得到响应,但是经常在通知后得到它.
下面引用的Android Doc部分中第二个强调的部分是为什么这是一个问题.如果我在收到购买请求的异步响应时将我的应用程序状态更新为“待处理”,因为文档似乎表明我应该这样做,那么如果通知发出后我的应用程序处于待处理状态,则该响应是否到来.是否应该说“当您从即时同步响应收到result_ok时”?
是Goole Play的错误吗(我手机上的Google Play版本为3.5.15,Android os版本为2.2)?我误会文档了吗? Docs只是错误的吗?静态测试产品是否有问题?还有其他问题吗?请注意,就我而言,一切都在UI线程中运行,因此这不是线程问题.
典型的非工作运行的日志输出显示在底部.
Android文档的相关部分(重点是我的):
Handling broadcast intents
A REQUEST_PURCHASE request also triggers two asynchronous responses
(broadcast intents). First, the Google Play application sends a
RESPONSE_CODE broadcast intent, which provides error information about
the request. If the request does not generate an error, the
RESPONSE_CODE broadcast intent returns RESULT_OK, which indicates that
the request was successfully sent. (To be clear, a RESULT_OK response
does not indicate that the requested purchase was successful; it
indicates that the request was sent successfully to Google Play.)Next, when the requested transaction changes state (for example, the
purchase is successfully charged to a credit card or the user cancels
the purchase), the Google Play application sends an IN_APP_NOTIFY
broadcast intent. This message contains a notification ID, which you
can use to retrieve the transaction details for the REQUEST_PURCHASE
request.Note: The Google Play application also sends an IN_APP_NOTIFY for
refunds. For more information, see Handling IN_APP_NOTIFY messages.Because the purchase process is not instantaneous and can take several
seconds (or more), you must assume that a purchase request is pending
from the time you receive a RESULT_OK message until you receive an
IN_APP_NOTIFY message for the transaction. While the transaction is
pending, the Google Play checkout UI displays an “Authorizing
purchase…” notification; however, this notification is dismissed
after 60 seconds and you should not rely on this notification as your
primary means of conveying transaction status to users. Instead, we
recommend that you do the following:
我的日志中的示例未按预期顺序进行:
MAKING REQUEST: PurchaseRequest
EXECUTING REQUEST: PurchaseRequest
IMEDIATE RESPONSE IN: PurchaseRequest, IS RESULT_OK
REQUEST ID: 1814990809059790249, PurchaseRequest
Receiver: Notify
Notify String in IN_APP_NOTIFY intent: android.test.purchased
PROCESSING NOTIFICATION
MAKING REQUEST: PurchaseInformationRequest
EXECUTING REQUEST: PurchaseInformationRequest
IMEDIATE RESPONSE IN: PurchaseInformationRequest, IS RESULT_OK
REQUEST ID: 602248989635492868, PurchaseInformationRequest
Receiver: purchase state changed
PROCESSING PURCHASE_STATE_CHANGE
newestMarketPurchaseState = PURCHASED
SetState on product 'Enterprise'. Message: PURCHASED
MAKING REQUEST: ConfirmNotificationsRequest
EXECUTING REQUEST: ConfirmNotificationsRequest
IMEDIATE RESPONSE IN: ConfirmNotificationsRequest, IS RESULT_OK
REQUEST ID: 693394902887436727, ConfirmNotificationsRequest
Receiver: Response Code = RESULT_OK
Receiver: Response Code requestId = 602248989635492868
PROCESSING RESPONSE
ASYNCH RESPONSE IN: PurchaseInformationRequest, IS RESULT_OK
Receiver: Response Code = RESULT_OK
Receiver: Response Code requestId = 1814990809059790249
PROCESSING RESPONSE
ASYNCH RESPONSE IN: PurchaseRequest, IS RESULT_OK
SetState on product 'Enterprise'. Message: PURCHASE PENDING
Receiver: Response Code = RESULT_OK
Receiver: Response Code requestId = 693394902887436727
PROCESSING RESPONSE
ASYNCH RESPONSE IN: ConfirmNotificationsRequest, IS RESULT_OK
Confirm Notifications Request returned asynch OK
解决方法:
我也遇到了同样的问题.根据问题Are Android broadcasts received in order?的答案,不能绝对保证将按发送顺序接收到意图.他们通常这样做,但不一定.因此,即使Google Play正确订购了它们,它们仍然可以按其他顺序到达.
我认为,唯一的解决方案是不假设RESPONSE_CODE到达的时间.在这方面,Android文档确实对我来说确实是错误的.响应代码应该应该通过回调而不是广播来实现.我不得不承认Google有时会变得很粗心.
标签:in-app-billing,android 来源: https://codeday.me/bug/20191201/2081379.html