test for internet connection in android login -
i want check internet connection. tried using code doesn't work. didn't got message (aucune connexion internet)
private boolean isconnectingtointernet(context applicationcontext){ connectivitymanager cm = (connectivitymanager) getsystemservice(context.connectivity_service); networkinfo ni = cm.getactivenetworkinfo(); if (ni == null) { // there no active networks. toast.maketext(getapplicationcontext(), "no internet", toast.length_long).show(); return false; } else return true; }
and
protected void onpostexecute(string s) { super.onpostexecute(s); loading.dismiss(); if(isconnectingtointernet(getapplicationcontext())) { showemployee(s); }else{ // show alert toast.maketext(mainactivity.this, "aucune connexion internet", toast.length_short).show(); } }
are fetching string s
internet , why using asynctask
? in case, should check isconnectingtointernet
before running asynctask
, not inside it.
in case, try in isconnectingtointernet
:
private boolean isconnectingtointernet(context applicationcontext){ connectivitymanager cm = (connectivitymanager) getsystemservice(context.connectivity_service); networkinfo ni = cm.getactivenetworkinfo(); return ni != null && ni.isconnectedorconnecting(); }
Comments
Post a Comment