Skip to content
Search

Android:Network

lastmod 2018-08-17created 2016-05-312 edits

Using a Network Connection.

You can use the network (when it's available) to store and retrieve data on your own web-based services. To do network operations, use classes in the following packages:

  • java.net.*
  • android.net.*

How to check the internet connection state using ConnectivityManager

//인터넷에 연결돼 있나 확인
ConnectivityManager connect = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
if (connect.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() ==  NetworkInfo.State.CONNECTED ||
    connect.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
        // 연결 돼있는 경우...
} else {
        // 연결 돼있지 않은 경우...
}

The source is as above, and running it requires the following two permissions.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.INTERNET" />

See also

Favorite site