Android InApp Billing : How to detect back press interrupting the purchase process? -
i'm trying implement inapp billing service iabhelper. manage go through full purchase process without problems.
//----------------------------------------------- public void billingservicelaunchpurchase(string item) { //----------------------------------------------- if (isnetworkavailablesync(getbasecontext())) { currbuyitem=item; billingconsummetype=1; mhelper.launchpurchaseflow(baseactivity.this, item, 10001, mpurchasefinishedlistener, ""); } else { onbillingservicefailed(); } } //----------------------------------------------- mpurchasefinishedlistener = new iabhelper.oniabpurchasefinishedlistener() { //----------------------------------------------- public void oniabpurchasefinished(iabresult result, purchase purchase) { if (result.isfailure()) { // handle error onbillingservicefailed(); return; } else if (purchase.getsku().equals(currbuyitem)) { billingserviceconsumeitem(); } } }; @override //----------------------------------------------------------------------- protected void onactivityresult(int requestcode, int resultcode, intent data) //----------------------------------------------------------------------- { if (billingserviceconnected) { if (!mhelper.handleactivityresult(requestcode, resultcode, data)) { super.onactivityresult(requestcode, resultcode, data); } else { // onactivityresult handled iabutil. } } else super.onactivityresult(requestcode, resultcode, data); }
however, cannot detect event when user launches purchase press backspace on google confirmation screen button "buy" interrupt it.
it neither triggers failure on oniabpurchasefinished nor triggers onactivityresult application stays in intermediary status.
please me solve problem.
according have understood question, searching purchase cancel event in app billing.
you can trigger via onactivityresult() method.put below code in onactivityresult() method. there simple reseult_cancel type shows user has been cancel purchasing.
if (mhelper == null) return; if (requestcode == 10001) { int responsecode = data.getintextra("response_code", 0); string purchasedata = data.getstringextra("inapp_purchase_data"); log.d("inapp_purchase_data", ">>>" + purchasedata); string datasignature = data.getstringextra("inapp_data_signature"); log.d("inapp_data_signature", ">>>" + datasignature); string continuationtoken = data .getstringextra("inapp_continuation_token"); log.d("inapp_continuation_token", ">>>" + continuationtoken); if (resultcode == result_ok) { try { log.d("purchasedata", ">>>"+purchasedata); jsonobject jo = new jsonobject(purchasedata); string sku = jo.getstring("productid"); alert("you have bought " + sku + ". excellent choice, adventurer!"); } catch (jsonexception e) { alert("failed parse purchase data."); e.printstacktrace(); } } else if (resultcode == result_canceled) { // } else if (resultcode == result_canceled) { toast.maketext(appmaintest.this, "sorry, have canceled purchase subscription.", toast.length_short).show(); } else if (resultcode == iabhelper.billing_response_result_item_already_owned) { toast.maketext(appmaintest.this, "item owned", toast.length_short).show(); } } }
or
you can handle manually using business logic. check if user cancel purchase product put flag user has been purchased or not if not call launchpurchaseflow() method again.
edit
ondestroy() method @override public void ondestroy() { super.ondestroy(); // important: log.d(tag, "destroying helper."); if (mhelper != null) mhelper.dispose(); mhelper = null; }
if have button can directly call launchpurchaseflow() method onclick event every time mhelper created new purchase.
or
if using in oncreate method , haven't button click event purchase product have give value null according knowledge.
hope solve problem.
Comments
Post a Comment