将 google play 计费库从 v4 更新到 v5 后,我无法获得订阅价格。 计费流程运行良好,我也可以购买产品。
我能够在 v4 上获得订阅产品的价格。
我已经试过了,但我没有得到价格。
if (billingClient.isReady()) {
QueryProductDetailsParams queryProductDetailsParams =
QueryProductDetailsParams.newBuilder()
.setProductList(
ImmutableList.of(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(ITEM_SKU_SUBSCRIBE)
.setProductType(BillingClient.ProductType.SUBS)
.build())).build();
billingClient.queryProductDetailsAsync(queryProductDetailsParams, new
ProductDetailsResponseListener() {
@Override
public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull List<ProductDetails> list) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
monthlyPriceTV.setText(list.get(0).getSubscriptionOfferDetails().get(0).getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice());
}
});
}
我没有收到任何错误或警告
任何帮助将不胜感激
您可以检查 billingClient 的响应值,如果功能不支持,告诉用户升级他们的 Play 商店。
private void queryProduct() {
QueryProductDetailsParams queryProductDetailsParams =
QueryProductDetailsParams.newBuilder()
.setProductList(productList)
.build();
billingClient.queryProductDetailsAsync(
queryProductDetailsParams,
(billingResult, list) -> {
// process returned productDetailsList
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
setProductDetailsList(list);
this.billingListener.onQueryProductSuccess(list);
} else if (billingResult.getResponseCode() == BillingResponseCode.FEATURE_NOT_SUPPORTED) {
Log.e(TAG, "Feature not supported");
ToastUtil.show(context, "Feature not supported, Please upgrade your Google Play Store");
this.billingListener.onQueryProductFailed(billingResult);
} else {
Log.e(TAG, billingResult.getDebugMessage());
this.billingListener.onQueryProductFailed(billingResult);
}
}
);
}
详见官方文档:https://developer.android.com/google/play/billing/integrate#process-the-result