提问人:Jorn Rigter 提问时间:11/17/2023 更新时间:11/17/2023 访问量:13
Google Play 结算查询PurchasesAsync 在存在有效订阅时返回空订阅列表
Google Play Billing queryPurchasesAsync returns empty subscriptions list while there is an active subscription
问:
通过该方法进行查询时,Google Play 结算库会返回一个空的订阅列表,而实际上存在有效的订阅。从 queryPurchasesAsync 的文档中:queryPurchasesAsync
仅返回有效订阅和未使用的一次性购买。此方法使用 Google Play 商店应用的缓存,而不发起网络请求。
我尝试清空Play商店缓存,但仍然返回一个空列表。
我使用的是 Play 结算库 6.0.1。这是我的相关代码:
private BillingClient billingClient;
private final Set<Purchase> purchases;
boolean billingClientConnected;
public static BillingManager getInstance(Activity activity) {
if (billingManager == null) {
billingManager = new BillingManager(activity);
}
return billingManager;
}
public BillingManager(Activity activity) {
productList = new ArrayList<>();
purchases = new HashSet<>();
init(activity);
}
private void init(Activity activity) {
// Create the billing client.
billingClient = BillingClient.newBuilder(activity)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build();
startBillingClientConnection();
}
public void startBillingClientConnection() {
if (billingClient != null) {
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
billingClientConnected = true;
// Do some other stuff..
}
}
@Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
billingClientConnected = false;
}
});
}
}
public void queryPurchases() {
if (!billingClientConnected) {
startBillingClientConnection();
} else {
QueryPurchasesParams subsPurchasesParams = QueryPurchasesParams.newBuilder()
.setProductType(BillingClient.ProductType.SUBS)
.build();
billingClient.queryPurchasesAsync(subsPurchasesParams,
new PurchasesResponseListener() {
@Override
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult,
@NonNull List<Purchase> purchaseList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
// Here I get an empty list.
// Handle all purchases that were successfully queried.
for (Purchase purchase : purchaseList) {
handlePurchase(purchase);
}
}
}
});
}
}
答: 暂无答案
评论