gpt4 book ai didi

android - 来自 Google Play 的应用内结算广播顺序不正确? (静态测试)

转载 作者:太空狗 更新时间:2023-10-29 12:53:06 25 4
gpt4 key购买 nike

应用内结算的 Android 文档似乎对以下问题非常清楚。在 REQUEST_PURCHASE 之后,您显示带有待处理 Intent 的结帐(很好,没问题),然后用户与结帐交互并点击购买按钮(在这种情况下,我使用的是静态产品 ID android.test.purchased).

现在我的广播接收器应该收到 RESPONSE_CODETHEN IN_APP_NOTIFY。好吧,这没有发生。有时我先收到回复,但经常是在收到通知后才收到。

下面引用的 Android 文档部分的第二个强调部分是为什么这是一个问题。如果我在收到对购买请求的异步响应时将我的应用程序中的状态更新为待处理,因为文档似乎表明我应该这样做,那么如果该响应是在通知之后出现的,我的应用程序就会陷入待处理状态。它应该说“当您从即时同步响应中收到 result_ok 时”吗?

是不是Goole Play的bug(我手机上的Google Play版本是3.5.15,Android os版本是2.2)?我误解了文档吗?文档是完全错误的吗?是静态测试产品的问题吗?是否还有其他问题?请注意,在我这边,一切都在 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? , 不能绝对保证 Intent 将按照发送的顺序接收。他们通常会这样做,但不一定。因此,即使 Google Play 正确订购了它们,它们仍然可以按其他顺序到达。

在我看来,唯一的解决办法是不假设 RESPONSE_CODE 到达的时间。在这方面,Android 文档在我看来确实是错误的。响应代码可能应该通过回调而不是广播来实现。我不得不承认 Google 有时会变得相当粗心。

关于android - 来自 Google Play 的应用内结算广播顺序不正确? (静态测试),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10022057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com