androidin-app-billingandroid-multiple-users

How to handle in-app billing on devices with multiple accounts?


I'm having problems to handle in-app billing inventory on devices with multiple accounts.

DEVICE 1:

DEVICE 2:

The code to handle the query inventory response is this:

@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
    if (result.isFailure()) {
        Log.d("billing", "inventory: failed (" + result.mMessage + ")");
        return;
    }

    Log.d("billing", "inventory: remove_ads purchased=" + inventory.hasPurchase("remove_ads");
}

The logcat output on DEVICE 1 is:

inventory: remove_ads purchased=true

And the logcat output on DEVICE 2 is:

inventory: remove_ads purchased=false

What am I missing? Thanks!


Solution

  • It was my mistake, this is what happened:

    1. Test purchase done using DEVICE 1 on the published version (release signature), purchase done successfully.
    2. I started working on the next version (debug signature) using DEVICE 1, but as the purchase was done on this device, google play billing cached the response and it returned true when I queried the inventory.
    3. After a while I started working using DEVICE 2, then the google play billing was not returning anything when I queried the inventory, because the purchase was not cached and the APK signature didn't match.

    It all started working when I signed the APK with the release signature and tested it on DEVICE 2.

    Conclusion: pay more attention with the signature and beware of cached responses