Java 如何通过Google Play计费库传递用户ID?

Java 如何通过Google Play计费库传递用户ID?,java,android,in-app-billing,play-billing-library,Java,Android,In App Billing,Play Billing Library,草案内容如下: 从2021年8月2日开始,所有新应用程序必须使用计费库版本3或更新版本。到2021年11月1日,现有应用程序的所有更新必须使用计费库版本3或更新版本 这种依赖性是什么: implementation "com.android.billingclient:billing:3.0.2" 如何将类似的用户ID传递给计费客户端?可以使用BillingFlowParams传递帐户ID和档案ID: String accountId = ""; Str

草案内容如下:

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

这种依赖性是什么:

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

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

可以使用
BillingFlowParams
传递
帐户ID
档案ID

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()
上可以从
购买中检索:

@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();
                    ...
                }
            }
        }
    }
}
@覆盖
PurchaseSupdated上的公共无效(@NonNull BillingResult BillingResult,@Nullable列表项){
if(items!=null&&items.size()>0){
用于(采购项目:项目){
if(item.getPurchaseState()==Purchase.PurchaseState.PURCHASED){
...
AccountIdentifiers=item.getAccountIdentifiers();
if(标识符!=null){
字符串accountId=标识符。getObfuscatedAccountId();
String profileId=identifiers.getObfuscatedProfileId();
...
}
}
}
}
}