android - in-app billing error : unable to buy item,error response 5 developer error -
i have in-app billing service set there 2 consumables , 1 non-consumable.
for non-consumable, checking purchase list , if item owned, want user refrain purchasing again , instead make benefit available. have 2 classes: guess.java (launcher file) , purchase.java (in-app billing setup file)
inside guess.java
intent intent = new intent(guess.this,purchase.class); intent.putextra("buy_2x", "buy_2x"); startactivity(intent);
the buy_2x non-consumable (buying-choice 2 in code below while consumables call buying choices 0 , 1) referring to. inside purchase.java code follows
public class purchase extends activity { iinappbillingservice mservice; private bundle extras; private int add=0;//add coins kitty private int buying_choice; private string item_sku_selection; private static final string tag = "com.apps.guess.inappbilling"; iabhelper mhelper; private serviceconnection mserviceconn; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); string base64encodedpublickey = "<64-char> long"; intent intent = getintent(); string buy2x_recd =intent.getextras().getstring("buy_2x"); //this class contains static variables , using choices //0,1,2...choice 2 non-consumable buy_2x if(userdata.getbuying_choice()!=2) item_sku_selection = selectbuyingchoice(userdata.getbuying_choice()); //callservice() method referred below if(buy2x_recd.equalsignorecase("buy_2x"))callservice(); mhelper = new iabhelper(this, base64encodedpublickey); mhelper.startsetup(new iabhelper.oniabsetupfinishedlistener() { public void oniabsetupfinished(iabresult result) { if (!result.issuccess()) { toast.maketext(getapplicationcontext(), "in-app billing setup failed: = ", toast.length_long).show(); log.d(tag, "in-app billing setup failed: "); } else { log.d(tag, "in-app billing set ok"); mhelper.launchpurchaseflow(purchase.this, item_sku_selection, 10001,mpurchasefinishedlistener, ""); mhelper.enabledebuglogging(true, tag); } } }); }//oncreate() ends public void callservice(){ mserviceconn = new serviceconnection() { @override public void onserviceconnected(componentname name, ibinder service) { mservice = iinappbillingservice.stub.asinterface(service); log.d("test", "mservice ready go!"); checkowneditems(); } @override public void onservicedisconnected(componentname name) { mservice = null; } }; bindservice(new intent("com.android.vending.billing.inappbillingservice.bind"), mserviceconn, context.bind_auto_create); } private void checkowneditems() { try { bundle owneditems = mservice.getpurchases(3, getpackagename(), "inapp", null); int response = owneditems.getint("response_code"); if (response == 0) { arraylist<string> ownedskus = owneditems.getstringarraylist("inapp_purchase_item_list"); arraylist<string> purchasedatalist = owneditems.getstringarraylist("inapp_purchase_data_list"); arraylist<string> signaturelist = owneditems.getstringarraylist("inapp_data_signature"); string continuationtoken = owneditems.getstring("inapp_continuation_token"); (int = 0; < purchasedatalist.size(); ++i) { string purchasedata = purchasedatalist.get(i); string signature = signaturelist.get(i); string sku = ownedskus.get(i); if(sku.equalsignorecase("buy_2x")) { alertdialog.builder builder = new alertdialog.builder(purchase.this); builder.settitle("purchased already"); builder.setmessage("you have purchased 2x option. want enable it?"); builder.setpositivebutton("yes!", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog1, int which) { toast.maketext(getapplicationcontext(), "you have decided double gains!.please wait...", toast.length_long).show(); int double_2x_value=2*getresources().getintarray(r.array.start_parameters)[2]; userdata.writedata(""+double_2x_value, purchase.this, userdata.get2xfile()); userdata.setwinningvalue(""+double_2x_value); userdata.writedata("true", purchase.this, userdata.getdoublexpurchasefile()); userdata.setbuy2x(true); userdata.setbuying_choice(0); dialog1.dismiss(); intent intent = new intent(purchase.this, com.glambleapps.guesstheword.guess.class); startactivity(intent); }}); builder.setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog1, int which) { dialog1.dismiss(); }}); alertdialog alert = builder.create(); alert.show(); break; } // purchase information // e.g. display updated list of products owned user } // if continuationtoken != null, call getpurchases again // , pass in token retrieve more items } else { toast.maketext(purchase.this, "no 2x purchase available on device",toast.length_long).show(); item_sku_selection=selectbuyingchoice(2); } } catch (remoteexception e) { // todo auto-generated catch block e.printstacktrace(); } } private string selectbuyingchoice(int buying_choice2) { string item_sku_selection=null; switch(buying_choice2){ case 0: item_sku_selection = "buy_200_coins"; add = 200; toast.maketext(getapplicationcontext(), "you have decided purchase 200 coins.please wait...", toast.length_long).show(); break; case 1: item_sku_selection = "buy_1200_coins"; add = 1200; toast.maketext(getapplicationcontext(), "you have decided purchase 1200 coins.please wait...", toast.length_long).show(); break; case 2: item_sku_selection = "buy_2x"; add = 0; toast.maketext(getapplicationcontext(), "you have decided double winnings!.please wait...", toast.length_long).show(); break; default: toast.maketext(getapplicationcontext(), "no buying choice", toast.length_short).show(); break; } //toast.maketext(getapplicationcontext(), "item_sku_selection = "+item_sku_selection, toast.length_short).show(); return item_sku_selection; } iabhelper.onconsumefinishedlistener mconsumefinishedlistener = new iabhelper.onconsumefinishedlistener() { public void onconsumefinished(purchase purchase, iabresult result) { if (result.issuccess()) { int total =add+integer.parseint(userdata.getcoins_remaining()); if(!(item_sku_selection.equalsignorecase("buy_2x"))) toast.maketext(getapplicationcontext(), "successful purchase done of "+add+" guess-coins!", toast.length_long).show(); if(item_sku_selection.equalsignorecase("buy_2x")){ int double_2x_value=2*getresources().getintarray(r.array.start_parameters)[2]; toast.maketext(getapplicationcontext(), "2x - double winnings! purchase successful.", toast.length_long).show(); userdata.setwinningvalue(""+double_2x_value); } add=0; intent intent = new intent(purchase.this, guess.class); startactivity(intent); } else { toast.maketext(getapplicationcontext(), "no purchase done", toast.length_long).show(); intent intent = new intent(purchase.this, guess.class); startactivity(intent); } } }; @override public void ondestroy() { super.ondestroy(); if (mhelper != null) mhelper.dispose(); mhelper = null; if(mserviceconn != null) { unbindservice(mserviceconn); mserviceconn=null; } } public void consumeitem() { mhelper.queryinventoryasync(mreceivedinventorylistener); } iabhelper.queryinventoryfinishedlistener mreceivedinventorylistener = new iabhelper.queryinventoryfinishedlistener() { public void onqueryinventoryfinished(iabresult result, inventory inventory) { if (result.isfailure()) { intent intent = new intent(purchase.this, guess.class); startactivity(intent); } else { mhelper.consumeasync(inventory.getpurchase(item_sku_selection), mconsumefinishedlistener); } } }; @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (!mhelper.handleactivityresult(requestcode, resultcode, data)) { super.onactivityresult(requestcode, resultcode, data); } if (resultcode == result_canceled) { toast.maketext(purchaseactivity.this,"sorry, have canceled coins purchase.",toast.length_short).show(); } } iabhelper.oniabpurchasefinishedlistener mpurchasefinishedlistener = new iabhelper.oniabpurchasefinishedlistener() { public void oniabpurchasefinished(iabresult result, purchase purchase) { if (result.isfailure()) { intent intent = new intent(purchase.this, guess.class); startactivity(intent); return; } else if (purchase.getsku().equals(item_sku_selection)) {consumeitem(); } } }; }//class ends
i getting following warning :
implicit intents startservice not safe: intent { act=com.android.vending.billing.inappbillingservice.bind } android.content.contextwrapper.bindservice:517 purchase.callservice:107 purchase.oncreate:68
the error follows:
iabhelper(25782): in-app billing error: unable buy item, error response: 5:developer error
the userdata.java stores values , writes datain text files. have no issues.
what issue? please help. thank you
are trying buy item logged on device googleplay developer account?
google doesn't allow it. should use different one.
in developer console, go account settings , add accounts test. then, logged 1 of them, try purchase item. should able achieve it.
edit:
checking documentation, i've found must test valid signed apk http://developer.android.com/google/play/billing/billing_reference.html
Comments
Post a Comment