about uscontact

Check network availability of your android phone

Author: zemna
Date: April 17, 2021
Share this:

현재 안드로이드 폰에서 와이파이가 연결가능한지, 3G가 연결가능한지 확인하는데 사용 가능한 유틸 클래스

사용하는 방법

  • 와이파이 상태 확인 : ZemnaNetworkInfo.IsWifiAvailable(현재 컨텍스트)
  • 3G 상태 확인 : ZemnaNetworkInfo.Is3GAvailable(현재 컨텍스트)
  • 둘중에 아무거나 연결 가능한지 확인 : ZemnaNetworkInfo.IsAnyAvailable(현재 컨텍스트)


[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]

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *


Professional software development agency estalished in Indonesia. We offers website setup, web application development, fulfillment service, and etc.
Follow us
Follow us to get latest news and tutorials.
2022 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️