hello friends, new web services making simple application establish connection.
below code.
public class mainactivity extends activity { textview text; string ip = "http://developer.android.com/index.html"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); text=(textview)findviewbyid(r.id.textview2); try{ url url=new url(ip); executereq(url); text.settext("connection available"); } catch(exception e){ text.settext("connectionn failed"); } } private void executereq(url url) throws ioexception{ httpurlconnection con=(httpurlconnection)url.openconnection(); con.setreadtimeout(10000); con.setconnecttimeout(10000); con.setrequestmethod("get"); con.setdoinput(true); con.setrequestmethod("head"); con.connect(); }
}
i have declared permission in manifest file can not finding fault.
please me in advance.
this code trigger networkonmainthreadexception
. try using asynctask
achieve this.
for more info: http://developer.android.com/training/basics/network-ops/connecting.html
Comments
Post a Comment