반응형
Notice
Recent Posts
Recent Comments
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
Total
관리 메뉴

Do Something IT

[안드로이드] 네트워크 체크 4g 본문

Android

[안드로이드] 네트워크 체크 4g

아낙시만더 2011. 9. 1. 12:10
반응형
4G 체크는 android 2.3.1 부터 지원한다.
package wiz.networktest.com;

ipackage wiz.networktest.com;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;

public class NetworkTest extends Activity {
	boolean isInternetWiMax = false;
	boolean isInternetWiFi = false;
	boolean isInternetMobile = false;
	
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

		if (cm.getActiveNetworkInfo() != null) {
			NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
			switch (activeNetwork.getType()) {
			case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크
				isInternetWiMax = true;
				break;
			case ConnectivityManager.TYPE_WIFI: // wifi망 체크
				isInternetWiFi = true;
				break;
			case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크
				isInternetMobile = true;
				break;
			}
		}else{
		   Toast.makeText(this,"네트워크가 연결되어 있지 않습니다. 확인해주세요").show();
		}
        Toast.makeText(this, "4g is "+isInternetWiMax + "\nwifi is "+isInternetWiFi +"\n3g is "+ isInternetMobile, Toast.LENGTH_LONG).show();
    }
}


다운로드 예제:
반응형
Comments