简体   繁体   中英

Android: get Google Play account associated with in-app billing

How can I get the email/ID of the Google Play account associated with an app?

I need this to show the user which account is taken into consideration for in-app billing. As far as I understood, Google in-app billing uses the account which downloaded the app, but I need to find a way to display this to the user, in case he has more than one account configured.

This would prevent users to complain not having their purchases recognized, when they have another account associated with the app.

I don't think there is a way to detect the account that the user will use during an in app purchase.

The only thing I can think of is querying the AccountManager to check if the user has more than one google account and show a msg saying something like: "You have more than one google account, make sure you are using the correct one before proceeding". The only problem with this approach is that you would need to add the required permissions to do this query.

There is no way to know the email which the user is buying.

Even using the Account Manager , returns you a whole list of all emails.

Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
   if (emailPattern.matcher(account.name).matches()) {
       String possibleEmail = account.name;
       ...
   }
}

It's not as simple as choosing the first of the list, since the user could buy with any email that is associated to the phone. You can use the AbstractAccountAuthenticator#getAccountRemovalAllowed , to know that account can not be deleted, and know which is the main mail (since you cannot delete the main mail), but even this may change, the user can change the main mail in any time.

I would like to know how to do this, but unfortunately there is no way. In my case, it's not essential money, so I send me as "payload" all email accounts of the phone concatenated, and all of these which would allow unlock premium content in my application, what can I lose some sales? It is likely, but I prefer that to a negative score in the market because a user buy premium content and could not be unlocked because I chose the wrong mail.

Actually is not possible to get from Google Play the account that downloaded the application. The suggestion is to create your own application user's account and only allow purchases after user registration (you can use whatever method you want to use).

And, for each purchase you link in your backed to the user's account. And, if the users log into another device using another Google account, if he log into your application using the right account, the access will be granted.

Google Play team is aware that this is not the best solution, and as I commented on this question , we are improving the API and as soon as we have an update, I'll post here too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM