在 android billing 5.0.0 中将多个产品添加到 queryProductDetailsAsync 的产品列表
Adding multiple products to productlist for queryProductDetailsAsync in android billing 5.0.0
在旧的 android 计费实施中,您将构建一个 sku 列表来查询产品:
List<String> skuList = new ArrayList<>();
skuList.add(SKU_POTION);
skuList.add(SKU_SWORD);
skuList.add(SKU_BOW);
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
新的计费实施更加复杂,似乎限制您只能将一种产品添加到查询列表:
ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.from(QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_POTION)
.setProductType(BillingClient.ProductType.INAPP)
.build());
QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder()
.setProductList(productList)
.build();
billingClient.queryProductDetailsAsync(
params,
new ProductDetailsResponseListener() {
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && productDetailsList != null) {
for (ProductDetails skuDetails : productDetailsList) {
mProductDetailsMap.put(skuDetails.getProductId(), skuDetails);
}
}
}
}
);
它让您为启动购买流程所需的 mProductDetailsMap 构建 productDetailsList 的 productList:
puchasestring=SKU_POTION;
initiatePurchaseFlow(mProductDetailsMap.get(puchasestring));
如何将多个产品添加到开始实施的产品列表中?我不想为每个项目重复整个代码段以添加到 mProductDetailsMap,这是我现在使用的原始 Pete 方法。
对于多个产品:
ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.from(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_POTION)
.setProductType(BillingClient.ProductType.INAPP)
.build(),
QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_SWORD)
.setProductType(BillingClient.ProductType.INAPP)
.build(),
QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_BOW)
.setProductType(BillingClient.ProductType.INAPP)
.build());
在旧的 android 计费实施中,您将构建一个 sku 列表来查询产品:
List<String> skuList = new ArrayList<>();
skuList.add(SKU_POTION);
skuList.add(SKU_SWORD);
skuList.add(SKU_BOW);
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
新的计费实施更加复杂,似乎限制您只能将一种产品添加到查询列表:
ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.from(QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_POTION)
.setProductType(BillingClient.ProductType.INAPP)
.build());
QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder()
.setProductList(productList)
.build();
billingClient.queryProductDetailsAsync(
params,
new ProductDetailsResponseListener() {
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && productDetailsList != null) {
for (ProductDetails skuDetails : productDetailsList) {
mProductDetailsMap.put(skuDetails.getProductId(), skuDetails);
}
}
}
}
);
它让您为启动购买流程所需的 mProductDetailsMap 构建 productDetailsList 的 productList:
puchasestring=SKU_POTION;
initiatePurchaseFlow(mProductDetailsMap.get(puchasestring));
如何将多个产品添加到开始实施的产品列表中?我不想为每个项目重复整个代码段以添加到 mProductDetailsMap,这是我现在使用的原始 Pete 方法。
对于多个产品:
ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.from(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_POTION)
.setProductType(BillingClient.ProductType.INAPP)
.build(),
QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_SWORD)
.setProductType(BillingClient.ProductType.INAPP)
.build(),
QueryProductDetailsParams.Product.newBuilder()
.setProductId(SKU_BOW)
.setProductType(BillingClient.ProductType.INAPP)
.build());