首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向Google计费库传递用户ID?

如何向Google计费库传递用户ID?
EN

Stack Overflow用户
提问于 2021-02-11 16:06:24
回答 1查看 902关注 0票数 1

文档的内容如下:

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

这就是这种依赖关系:

代码语言:javascript
复制
implementation "com.android.billingclient:billing:3.0.2"

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-11 16:06:24

可以通过accountIdprofileId传递BillingFlowParams

代码语言:javascript
复制
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()上,可以从Purchase检索AccountIdentifiers

代码语言:javascript
复制
@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();
                    ...
                }
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66158316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档