Tag:android network connection
/** * Determine if the mobile network is on * * @param context * @return */public static Boolean isnetenabled (context context) {Telephonymanager TM = (Telephonymanager) context.getsystemservice (Context.telephony_service), if (tm! = null) {if (Tm.getnetworktype ()! = Telephonymanager.network_type_unknown) {log.i ("SJF", "mobile network is turned on"); return true;}} LOG.I ("SJF", "mobile network not yet turned on"); return false;} /** * Determine if WiFi network is on * * @param context * @return */public static Boolean iswifienabled (context context) {Wifimanager wm = (Wifimanager) Context.getsystemservice (Context.wifi_service), if (wm! = null && wm.iswifienabled ()) {LOG.I (" SJF "," WiFi network is turned on "); return true; LOG.I ("SJF", "WiFi network not turned on"); return false;} /** * Determine if the mobile network is connected successfully * * @param context * @return */public static Boolean isnetcontected (context context) {Connectivitymana Ger cm = (Connectivitymanager) context.getsystemservice (Context.connectivity_service); Networkinfo info = cm.getnetworkinfo (connectivitymanager.type_mobile); if (cm! = NULL && info! = NULL && in Fo. IsConnected ()) {log.i ("SJF", "Mobile network Connection succeeded"); return true; LOG.I ("SJF", "Mobile network Connection Failed"); return false;} /** * Determine if WiFi connection is successful * * @param context * @return */public static Boolean iswificontected (context context) {Connectivityman Ager cm = (Connectivitymanager) context.getsystemservice (Context.connectivity_service); Networkinfo info = cm.getnetworkinfo (Connectivitymanager.type_wifi), if (info! = null && info.isconnected ()) { LOG.I ("SJF", "WiFi network connection succeeded"); return true; LOG.I ("SJF", "WiFi network Connection Failed"); return false;} /** * Determine if mobile network and WiFi is on * * @param context * @return */public static Boolean isnetworkenabled (context context) {return (IsN Etenabled (context) | | Iswifienabled (context));} /** * Determine if the mobile network and WiFi are connected successfully * @param context * @return */public static Boolean isnetworkconnected (context context) {return (IS Wificontected (context) | | Isnetcontected (context));}
[Android] Determines if a network connection is available