Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get non-primary purchase account email address

Prior to the introduction of Android 3.0, the first com.google account registered on a phone was the primary account, and the only account used by Android Market.

On devices on Android 3.0 and up I can no longer rely on this (Account[0]) to get the customer's email address.

Is there a way to tell which account com.google account is currently making the purchase?

(all I need is the index into the Account[] array for account type com.google. I can get the email address once I have the relevant index)

like image 266
ef2011 Avatar asked Jan 24 '12 20:01

ef2011


People also ask

How do I choose which account to send the email from?

Change your default email accountSelect File > Account Settings > Account Settings. From the list of accounts on the Email tab, select the account you want to use as the default account. Select Set as Default > Close.

What is a secondary email address?

A Secondary Email Address is an email address someone would use as an alternative for email communication. For example, a Contact's primary email address may be [email protected] but sometimes they send an email message from [email protected].


2 Answers

I am afraid it's not possible. From what I've found it looks like that the account making the in-app-purchase is the account used to install the app, which you don't know. I guess it might be possible to read it from the Play store application database on rooted phones.

It looks like that it's not even possible to find the purchasing account after the purchase has been done using the Google Play Android Developer API, not sure why is that though.

If you, by any chance, find that out, let me know.

like image 165
cermak.cz Avatar answered Sep 23 '22 12:09

cermak.cz


I just did a quick google search and came across this on this site here.

You can use AccountManager.getAccounts or AccountManager.getAccountsByType to get a list of all account names on the device. Fortunately, for certain account types (including com.google), the account names are email addresses. Example snippet below.

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;
        ...
    } }

Note that this requires the GET_ACCOUNTS permission:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

More on using AccountManager can be found at the Contact Manager sample code in the SDK.

like image 24
mpeerman Avatar answered Sep 23 '22 12:09

mpeerman