기술참고자료/Android | 2011. 5. 6. 13:33
public class ULNetworkReceiver extends BroadcastReceiver {
private Activity activity;
public ULNetworkReceiver() {
super();
}
public ULNetworkReceiver(Activity activity) {
this.activity = activity;
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// 네트웍에 변경이 일어났을때 발생하는 부분
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
try {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
NetworkInfo mobNetInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
WifiManager wifiManager =
(WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if(wifiInfo != null) {
/** WIFI 활성화 했고, AP 사용가능 */
if(wifiInfo.getIpAddress()>0 && wifiInfo.getSSID()!=null
&& wifiInfo.getSupplicantState().toString().equals("COMPLETED")) {
}
/** WIFI 활성화 했지만, AP 사용불가 */
else if(wifiInfo.getIpAddress()==0&&wifiInfo.getSSID()==null
&& (!wifiInfo.getSupplicantState().toString().equals("UNINITIALIZED")
|| wifiInfo.getSupplicantState().toString().equals("INACTIVE")
|| wifiInfo.getSupplicantState().toString().equals("SCANNING"))) {
Log.e("net info >>> ", "wifi use / AP not use ...");
}
/** WIFI 설정을 활성화 하지않은 경우/ 3G 사용가능할때 */
else if(activeNetInfo!=null && activeNetInfo.getTypeName().equals("mobile") &&
(wifiInfo.getSupplicantState().toString().equals("UNINITIALIZED")
|| wifiInfo.getSupplicantState().toString().equals("SCANNING")
|| wifiInfo.getSupplicantState().toString().equals("INACTIVE") )) {
Log.e("net info >>> ", "wifi not use / 3G success ...");
}
/** 3G, WIFI 둘 다 없을 경우 */
else {
Log.e("getSupplicantState >>> ", wifiInfo.getSupplicantState().toString()+"...");
}
}
} catch (Exception e){
}
}
}
}
[Android] Parcelable을 이용해 액티비티간 인텐트로 객체넘기기 (1) | 2011.05.06 |
---|---|
[Android] Wifi 다루기 (0) | 2011.05.06 |
진저브레드관련 - Android App 개발시 주의사항요청(CTS 승인이슈건) (0) | 2011.05.06 |
[안드로이드] Disable scroll view action (0) | 2011.05.04 |
SKT - 안드로이드 출시 단말별 해상도 (0) | 2011.04.28 |
Recent Comments