The example in this article describes how Java gets the network type. Share to everyone for your reference. as follows:
/**** * Get Network type * * @param context * @return/public static String Getnettype (context context) {try {Connectiv
Itymanager connectmgr = (connectivitymanager) context. Getsystemservice (Context.connectivity_service);
Networkinfo info = Connectmgr.getactivenetworkinfo ();
if (info = = null) {return "";
if (info.gettype () = = Connectivitymanager.type_wifi) {return "WIFI"; else if (info.gettype () = = Connectivitymanager.type_mobile) {if (info.getsubtype () = = Telephonymanager.network_type_c
DMA) {return "CDMA";
else if (info.getsubtype () = = Telephonymanager.network_type_edge) {return "EDGE";
else if (info.getsubtype () = = telephonymanager.network_type_evdo_0) {return "EVDO0";
else if (info.getsubtype () = = telephonymanager.network_type_evdo_a) {return "Evdoa";
else if (info.getsubtype () = = Telephonymanager.network_type_gprs) {return "GPRS"; }/* Else if (info.getsubtype () = * TELEPHONYMANAGER.NETWORK_TYPE_HSDPA) {return "HSDPA";} else * IF (info. Getsubtype () = = Telephonymanager.network_type_hspa) {* return "HSPA";}
else if (info.getsubtype () = = * Telephonymanager.network_type_hsupa) {return "HSUPA";}
*/Else if (info.getsubtype () = = Telephonymanager.network_type_umts) {return "UMTS";
else {return "3G";
} else {return "";
The catch (Exception e) {return ";
}
}
I hope this article will help you with your Java programming.