java - making the app work for all android versions -
i have created jsonobject pulls data server works on android versions less 3 (old ones). code make work on versions??
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); defaulthttpclient client; client = new defaulthttpclient(); httpget = new httpget("http://saurabhgoyal.comoj.com/json_test.php"); httpresponse r; try { r = client.execute(get); httpentity e = r.getentity(); inputstream is=e.getcontent(); inputstreamreader isr=new inputstreamreader(is); bufferedreader reader=new bufferedreader(isr); string results=reader.readline(); toast.maketext(this, results, toast.length_short).show(); } catch (clientprotocolexception e1) { // todo auto-generated catch block toast.maketext(this, "failure", toast.length_short).show(); e1.printstacktrace(); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); }
you shouldn't network calls on ui thread need use separate thread or asynctask
network call in.
in versions below 3.0 away doing that, in 3.0 networkonmainthreadexception
when that.
Comments
Post a Comment