In-app purchases with multiple accounts In-app purchases with multiple accounts android android

In-app purchases with multiple accounts


It seems like there isn't a one way road to solve this, but let's try do this.

  1. When the user first install the app get his/her primary email or all accounts on the device

  2. Ask the user what email will they be using for future payment/ or which account is active for google play.

    you can use this code to get the account

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

    Don't forget to ask for permission

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

    After the user selects the email, you can send a link via email to confirm this email address

  3. Lead all the payment to that specific email.

Method 2

Use the new "Send & Receive money using Gmail" future

  1. Create a email intent and send specific data to the email intent and make payments.

  2. Upon success, send a code to the user email

  3. Use the code to activate whatever purchased they make.

Method 3

Use another payment library or gateway for your in app purchase instead of Google play.


It is sure a bug in the in-app billing service apis.

This is a similar question and as mentioned in one of the answers, may be you need to introduce login mechanism and store the purchases made from an account to your server or locally on the device in an encrypted file or something similar.


I had ran into same problem couple of months later.After hours of finding solutions and all i came up with a work around something like this,

You can use OAuth 2.0.

But you also have to manage it from your backend.I am not a backend developer so i didnt know how exactly it does in backend but at app side i have done something like this,

You can use the first Google account allowing authentication on your serve side. OAuth 2.0 is a tool that simplifies and get developers an easy way to allow users to access your application. The OAuthHmacSigner class does manages the authentication.

signer = new OAuthHmacSigner();signer.clientSharedSecret = Constants.CONSUMER_SECRET;

Then the Android activity uses the following code to launch the OAuth flow :

launchOauth.setOnClickListener(new View.OnClickListener() {    public void onClick(View v) {        startActivity(new Intent().setClass(v.getContext(),            PrepareRequestTokenActivity.class));    }});

In order to get an OAuth 2.0 access token, you simply need to call:

AccountManager.getAuthToken()

I Hope this might help :)