问题
I'm developing an app that contains In App Billing non consumable product (Life time Subscription).
User has one email associated with Play Store on his device.
Scenario:
User A create new account using user1@test.com and purchase Lifetime Subscription and logout.
User B create new account using user2@test.com and trying to purchase.
but he get response BillingClient.BillingResponse.ITEM_ALREADY_OWNED
.
How do i differ each user to buy item?
I'm using 'com.android.billingclient:billing:2.2.1'
回答1:
If you are using Firebase authentication then you can get user's unique id using String uid = FirebaseAuth.getInstance().getCurrentUser().getUid()
and you can use this Id at the time of purchase like -
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails).setObfuscatedAccountId(uid)
.build();
BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);
Also in your database use this as unique identifier to check whether user has the subscriotion or not.
来源:https://stackoverflow.com/questions/63130255/google-in-app-billing-differentiate-user-accounts