如何向 Google Play Billing Library 传递用户 ID?

问题描述 投票:0回答:1

文档内容如下:

从 2021 年 8 月 2 日开始,所有新应用都必须使用计费库版本 3 或更高版本。到 2021 年 11 月 1 日,现有应用程序的所有更新都必须使用计费库版本 3 或更高版本。

这将是这个依赖项:

implementation "com.android.billingclient:billing:3.0.2"

如何向计费客户端传递类似用户 ID 的内容?

java android in-app-billing play-billing-library
1个回答
2
投票

可以通过

accountId
profileId
BillingFlowParams
:

String accountId = "";
String profileId = "";

BillingFlowParams.Builder builder = BillingFlowParams.newBuilder().setSkuDetails(skuDetail);
if (this.accountId != null) {builder.setObfuscatedAccountId(accountId);}
if (this.profileId != null) {builder.setObfuscatedProfileId(profileId);}
BillingFlowParams billingFlowParams = builder.build();

然后在

onPurchasesUpdated()
上,可以从 AccountIdentifiers
 检索 
Purchase

@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> items) {
    if (items != null && items.size() > 0) {
        for (Purchase item : items) {
            if (item.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
                ...
                AccountIdentifiers identifiers = item.getAccountIdentifiers();
                if (identifiers != null) {
                    String accountId = identifiers.getObfuscatedAccountId();
                    String profileId = identifiers.getObfuscatedProfileId();
                    ...
                }
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.