gpt4 book ai didi

Android - queryPurchaseHistoryAsync 购买列表在其他设备上为空

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:53:16 26 4
gpt4 key购买 nike

我正在尝试在我的应用中实现新的 Google Play 结算服务,并尝试使用 queryPurchaseHistoryAsync() 方法和 Purchase 检索我已购买的应用内商品 列表始终为空且包含 0 个元素。

代码在我购买该商品的设备上运行良好,但在我具有相同 Google 帐户的其他设备上,它没有返回任何内容。

也与 Documentation 中一样, queryPurchaseHistoryAsync() 应该与 Google 同步以获取购买历史记录,但由于某种原因它似乎没有同步。

我的代码是:

BillingClient billingClient = BillingClient.newBuilder(getApplicationContext()).setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
if(responseCode == BillingClient.BillingResponse.OK) {
//Do something
}
}
}).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(int responseCode) {
if(responseCode == BillingClient.BillingResponse.OK) {
//Response is OK and working fine
}
}

@Override
public void onBillingServiceDisconnected() {
//Do something
}
});

billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
if(responseCode == BillingClient.BillingResponse.OK) {
//Always returning 0 size() of purchasesList
Toast.makeText(getApplicationContext(), "There are " + purchasesList.size() + " items you've purchased.", Toast.LENGTH_LONG).show();
}
}
});

这段代码究竟哪里出错了?

非常感谢。

最佳答案

您是否在 onBillingSetupFinished() 之后调用了 queryPurchaseHistoryAsync()

在您的源代码上调用 onBillingSetupFinished() 之前,您似乎确实调用了 queryPurchaseHistoryAsync()。

您可以在this doc中查看以下代码

private BillingClient mBillingClient;
...
mBillingClient = BillingClient.newBuilder(mActivity).setListener(this).build();
mBillingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
if (billingResponseCode == BillingResponse.OK) {
// The billing client is ready. You can query purchases here.

}
}
@Override
public void onBillingServiceDisconnected() { }
});

关于Android - queryPurchaseHistoryAsync 购买列表在其他设备上为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50941340/

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