In-app purchases with multiple accounts

AndroidGoogle PlayGoogle Play-ServicesIn App-BillingAndroid Billing

Android Problem Overview


I am facing a problem with in app purchases/subscriptions:

If there are multiple accounts on the device, I can't get the purchases, which were made with the second account. This can sometimes be temporarily fixed, by installing the app from the Google Play web interface, but after a while, the purchases won't appear in the query, forcing the user to reinstall.

I am using the IabHelper classes from this sample.

Doing some Google searches, I found that this bug exists since a while, but unfortunately I couldn't find out if the error is in the IabHelper classes or on Google's side.

I'd like to draw attention to Google, so they provide a proper fix for this, either in the IabHelper classes or in the Play Services or to provide information, how this should be handled.

I am using the code in an app with (at the time of writing) 900.000 active user installs and I have to trigger quite a lot of refunds, due to this.

If there is a fix for this, which I missed, please let me know.

Edit: Sometimes it's not possible at all to retrieve the purchases, even if there is only one account on the phone.

Android Solutions


Solution 1 - Android

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

  1. 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.

Solution 2 - Android

It is sure a bug in the in-app billing service apis. https://stackoverflow.com/questions/15263889/does-in-app-billing-support-multiple-accounts">

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.

Solution 3 - Android

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 :)

Solution 4 - Android

I have two accounts, but one does not work. What I did is I went into android's settings, and then went into account preferences. I changed my main account from the one that does not work to the working one. Then I assigned the new account to be the main one for all of my applications, including google play. That worked for me. Sometimes, if it does not work for some reason, you can also go online and access the Google Play store from the internet.

Solution 5 - Android

Try to get dup...duplicate dot with file signature ending in .apk or .xcode

Solution 6 - Android

As others have noted, this is a bug with the Google Play Billing Library. If it affects you, star this issue on https://issuetracker.google.com/issues/139597485 so Google can notice it (really?) and start working on a fix.

Solution 7 - Android

I'm not sure if this is the answer you're searching for, but perhaps setting up a shared Google Play Family Library would suffice. It works for up to 5 users sharing the same purchases (app, music, movies, etc), if desired.

(See: https://support.google.com/googleplay/answer/7007852?hl=en)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionstefpleView Question on Stackoverflow
Solution 1 - AndroidLucien MendelaView Answer on Stackoverflow
Solution 2 - AndroidpsykidView Answer on Stackoverflow
Solution 3 - AndroidHardik ChauhanView Answer on Stackoverflow
Solution 4 - AndroidPenguini_The_PenguinView Answer on Stackoverflow
Solution 5 - AndroidPython ProView Answer on Stackoverflow
Solution 6 - Androidc0dehunterView Answer on Stackoverflow
Solution 7 - Androidrst_ackView Answer on Stackoverflow