Android:Network
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.*
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 {
// 연결 돼있지 않은 경우...
}
소스는 위와 같으며 위의 소스를 실행하기 위해선 다음의 두 퍼미션이 필요하다.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />