java - check internet connection on android (eclipse) -
java - check internet connection on android (eclipse) -
i need code algorithm in android eclipse programming :
if net connection = connect open programme else show error_activity.xml
create class connectiondetector , set below code in class:
private context _context; public connectiondetector(context context) { this._context = context; } public boolean isconnectingtointernet() { connectivitymanager connectivity = (connectivitymanager) _context .getsystemservice(context.connectivity_service); if (connectivity != null) { networkinfo[] info = connectivity.getallnetworkinfo(); if (info != null) (int = 0; < info.length; i++) if (info[i].getstate() == networkinfo.state.connected) { homecoming true; } } homecoming false; }
// ever want check net create object of class , phone call method below doing:
// in activity define globals:
boolean _isinternetpresent = false; connectiondetector _cd;
//in oncreate
_cd = new connectiondetector(getapplicationcontext()); _isinternetpresent = _cd.isconnectingtointernet();
and check this:
if (_isinternetpresent) { // work here } else { // no internet,please seek again. }
as fresher giving finish code.please seek understand each , every step,how code working.
java android eclipse
Comments
Post a Comment