android - InAppBillingService fails to bind -



android - InAppBillingService fails to bind -

i'm doing basic in app billing , service fails bind.

here main activity:

public class mainactivity extends activity { iinappbillingservice mservice; serviceconnection connection; string inappid = "android.test.purchased"; // replace in-app // product id @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); connection = new serviceconnection() { @override public void onservicedisconnected(componentname name) { mservice = null; } @override public void onserviceconnected(componentname name, ibinder service) { mservice = iinappbillingservice.stub.asinterface(service); } }; getapplicationcontext() .bindservice( new intent( "com.android.vending.billing.inappbillingservice.bind"), connection, context.mode_private); button purchasebtn = (button) findviewbyid(r.id.purchase); purchasebtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { arraylist skulist = new arraylist(); skulist.add(inappid); bundle queryskus = new bundle(); queryskus.putstringarraylist("item_id_list", skulist); bundle skudetails; seek { skudetails = mservice.getskudetails(3, getpackagename(), "inapp", queryskus); int response = skudetails.getint("response_code"); if (response == 0) { arraylist<string> responselist = skudetails .getstringarraylist("details_list"); (string thisresponse : responselist) { jsonobject object = new jsonobject(thisresponse); string sku = object.getstring("productid"); string cost = object.getstring("price"); if (sku.equals(inappid)) { system.out.println("price " + price); bundle buyintentbundle = mservice .getbuyintent(3, getpackagename(), sku, "inapp", "bgoa+v7g/yqdxvkrqq+jtfn4uqzbpiqjo4pf9rzj"); pendingintent pendingintent = buyintentbundle .getparcelable("buy_intent"); startintentsenderforresult( pendingintent.getintentsender(), 1001, new intent(), integer.valueof(0), integer.valueof(0), integer.valueof(0)); } } } } grab (remoteexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (jsonexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (sendintentexception e) { // todo auto-generated grab block e.printstacktrace(); } } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == 1001) { string purchasedata = data.getstringextra("inapp_purchase_data"); if (resultcode == result_ok) { seek { jsonobject jo = new jsonobject(purchasedata); string sku = jo.getstring(inappid); toast.maketext( mainactivity.this, "you have bought " + sku + ". first-class choice,adventurer!", toast.length_long).show(); } grab (jsonexception e) { system.out.println("failed parse purchase data."); e.printstacktrace(); } } } } @override public void ondestroy() { super.ondestroy(); if (connection != null) { unbindservice(connection); } }

}

when run app, bindservice method returns false , mservice null. log gives me message:

implicit intents startservice not safe: intent { act=com.android.vending.billing.inappbillingservice.bind } android.content.contextwrapper.bindservice:517 com.raico.coinage.mainactivity.oncreate:51 android.app.activity.performcreate:5231

change mainactivity.oncreate() phone call getapplicationcontext().bindservice() this:

intent serviceintent = new intent("com.android.vending.billing.inappbillingservice.bind"); serviceintent.setpackage("com.android.vending"); getapplicationcontext().bindservice(serviceintent, connection, context.mode_private);

this create intent explicit safer , should work on lollipop too.

android

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -