Android In-app billing purchased items -
i following tutorial code in-app billing items , manage make good, when want know if user purchased item o not, false, when test others devices have beta tester account.
this use 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 { // user have 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 code purchase 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 test app in real device account on beta testers, code works fine when buy item, when close app , open again, first code sais account didnt buy item.
you're consuming product after purchase returns.
see here consumable / non-consumable products: https://developer.android.com/google/play/billing/api.html#consumetypes
Comments
Post a Comment