Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Simple Developer
Simple Developer
현재 안드로이드 폰에서 와이파이가 연결가능한지, 3G가 연결가능한지 확인하는데 사용 가능한 유틸 클래스
사용하는 방법
Source
[code language=”java”] import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo;
public class ZemnaNetworkInfo {
public static boolean IsWifiAvailable(Context context) { return IsNetworkAvailable(context, ConnectivityManager.TYPE_WIFI); }
public static boolean Is3GAvailable(Context context) { return IsNetworkAvailable(context, ConnectivityManager.TYPE_MOBILE); }
public static boolean IsAnyAvailable(Context context) { if (IsWifiAvailable(context)) return true; if (Is3GAvailable(context)) return true; return false; }
private static boolean IsNetworkAvailable(Context context, int networkType) { ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); boolean bConnect = false; try { if (connMgr == null) return false;
NetworkInfo info = connMgr.getNetworkInfo(networkType); bConnect = (info.isAvailable() && info.isConnected()); } catch (Exception e) { return false; }
return bConnect; } } [/code]