Question

in my app user can buy ad removal, I keep this item (no consume). So I have fragment in my main activity that check if user bought item.

public class BillingInventoryFragment extends Fragment {
// Helper billing object
private IabHelper mHelper;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);

    initialiseBilling();
}


private void initialiseBilling() {
    if (mHelper != null) {
        return;
    }

    // Create the helper, passing it our context and the public key to verify signatures with
    mHelper = new IabHelper(getActivity(), BillingUtils.getApplicationKey());

    // Enable debug logging (for a production application, you should set this to false).
    mHelper.enableDebugLogging(true);

    // Start setup. This is asynchronous and the specified listener will be called once setup completes.
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        @Override
        public void onIabSetupFinished(IabResult result) {
            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) {
                return;
            }

            // Something went wrong
            if (!result.isSuccess()) {
                Log.e(getActivity().getApplicationInfo().name, "Problem setting up in-app billing: " + result.getMessage());
                return;
            }

            // IAB is fully set up. Now, let's get an inventory of stuff we own.
            mHelper.queryInventoryAsync(iabInventoryListener());
        }
    });
}


/**
 * Listener that's called when we finish querying the items and subscriptions we own
 */
private IabHelper.QueryInventoryFinishedListener iabInventoryListener() {
    return new IabHelper.QueryInventoryFinishedListener() {
        @Override
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) {
                return;
            }

            // Something went wrong
            if (!result.isSuccess()) {
                Log.d(TAG, String.format("result not success, result = %s", result) );
                return;
            }

            // Do your checks here...

            // Do we have the premium upgrade?
            Purchase purchasePro = inventory.getPurchase(BillingUtils.SKU_PRO); // Where BillingUtils.SKU_PRO is your product ID (eg. permanent.ad_removal)
            Log.d(TAG, String.format("Purchase pro = %s", purchasePro));
            BillingUtils.isPro = (purchasePro != null && BillingUtils.verifyDeveloperPayload(purchasePro));

            // After checking inventory, re-jig stuff which the user can access now
            // that we've determined what they've purchased
            BillingUtils.initialiseStuff();
        }
    };
}

/**
 * Very important!
 */
@Override
public void onDestroy() {
    super.onDestroy();

    if (mHelper != null) {
        mHelper.dispose();
        mHelper = null;
    }
}

}

Everything works on one device but when I tested it on second device:

inventory.getPurchase(BillingUtils.SKU_PRO);

returns null.

When I try buy item again on this second device, I can't because I own it.

No correct solution

OTHER TIPS

If you are sure that you bought this item successfully.It may be a problem related with used Gmail You should use the same Gmail in the two devices because Google is identifying its users using the registered Gmail on device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top