i was following a tutorial to code In-app billing items and i manage to make all good, but when i want to know if the user purchased an item o not, its always false, even when i test it with others devices that have a beta tester account.
This is what i use to get the item purchased:
mHelper = new IabHelper(MainActivity.this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
IabHelper.QueryInventoryFinishedListener mGotInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// handle error here
}
else {
// does the user have the premium upgrade?
boolean mIsPremium = inventory.hasPurchase(ITEM_SKU);
// update UI accordingly
Toast.makeText(getApplicationContext(), "" + mIsPremium, Toast.LENGTH_LONG).show();
if(mIsPremium){
buy.setVisibility(View.INVISIBLE);
}
}
}
};
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
And this is the code to purchase that item:
buy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mHelper.launchPurchaseFlow(MainActivity.this, ITEM_SKU, 10001,
new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
return;
} else if (purchase.getSku().equals(ITEM_SKU)) {
mHelper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
} else {
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
buy.setVisibility(View.GONE);
} else {
}
}
});
}
}
});
}
}
}, "mypurchasetoken");
}
});
When i test the app in a real device with the account on my beta testers, the code works fine when buy the item, but when i close the app and open it again, the first code sais that the account didnt buy the item.