本文介绍了未收到使用 API v3 的 Android 应用内购买结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Android In-App Billing 的第 3 版 API,但遇到了以下问题:

I'm trying to work my way through the version 3 API of Android In-App Billing and have come across the following issue:

如果我使用 launchPurchaseFlow,它按预期显示购买对话框,让我完成购买.购买完成后,如果我再次请求 SKU 详细信息,则该产品将被报告为拥有.因此,购买流程本身按预期进行.

If I start a purchase with launchPurchaseFlow, it displays the purchase dialog as expected and let's me complete the purchase. After the purchase is completed, the product is then reported as owned if I request the SKU details again. So the purchase process itself works as expected.

不起作用的是购买通知本身.我传递给 launchPurchaseFlowOnIabPurchaseFinishedListener 永远不会被调用.无论是取消购买还是完成购买.

What doesn't work are the notifications of the purchase itself. The OnIabPurchaseFinishedListener that I pass to launchPurchaseFlow never gets called. Neither if I cancel the purchase nor if I complete it.

我为 IabHelper 类打开日志记录并在 LogCat 中获得以下输出:

I turned on logging for the IabHelper class and get the following output in LogCat:

IabHelper: Starting in-app billing setup.
IabHelper: Billing service connected.
IabHelper: Checking for in-app billing 3 support.
IabHelper: In-app billing version 3 supported for <my app>
IabHelper: Subscriptions AVAILABLE.

IabHelper: Starting async operation: refresh inventory
IabHelper: Querying owned items, item type: inapp
IabHelper: Package name: <my app>
IabHelper: Calling getPurchases with continuation token: null
IabHelper: Owned items response: 0
IabHelper: Continuation token: null
IabHelper: Querying SKU details.
IabHelper: Got sku details: <my test product>
IabHelper: Querying owned items, item type: subs
IabHelper: Package name: <my app>
IabHelper: Calling getPurchases with continuation token: null
IabHelper: Owned items response: 0
IabHelper: Continuation token: null
IabHelper: Querying SKU details.
IabHelper: Ending async operation: refresh inventory

IabHelper: Starting async operation: launchPurchaseFlow
IabHelper: Constructing buy intent for <my test product>, item type: inapp
IabHelper: Launching buy intent for <my test product>. Request code: 1

到此结束.

我的活动收到 onPause() 显示购买对话框和 时的事件onResume() 对话框再次消失时的事件(如果购买被取消或完成).除了 System.out.println(...) 之外,这两个事件目前在我的应用程序中什么都不做.

My activity receives an onPause() event when the purchase dialog is shown and an onResume() event when the dialog goes away again (both, if the purchase is cancelled or completed). Both of these events currently do nothing in my app other than a System.out.println(...).

这是 API 中的错误吗?或者我需要先设置什么?任何帮助将不胜感激.

Is this a bug in the API? Or is there something I need to set up first? Any help would be appreciated.

推荐答案

翻阅IabHelper的源码,发现问题:

Digging through the source for IabHelper, I found the problem:

购买意向的结果会发送到Activity的onActivityResult(...) 方法.从那里,它需要手动转发到 IabHelper's handleActivityResult(...) 方法,如下所示:

The result of the purchasing intent will be sent to the Activity's onActivityResult(...) method. From there, it needs to be manually forwarded to the IabHelper's handleActivityResult(...) method with something like this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (myIabHelper.handleActivityResult(requestCode, resultCode, data)) return;
    super.onActivityResult(requestCode, resultCode, data);
}

这解决了成功购买和中止购买的问题.

This fixes the issue, both for successful and aborted purchases.

耶!"全面的文档...

"Yay!" for comprehensive documentation...

这篇关于未收到使用 API v3 的 Android 应用内购买结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 18:34