Android

Android wifi state Receiver

Machine_웅 2022. 10. 25. 09:22
728x90
반응형
 @Override
    protected void onStart() {
        super.onStart();
        IntentFilter intentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
        registerReceiver(wifiStateReceiver, intentFilter);
    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(wifiStateReceiver);
    }

    private BroadcastReceiver wifiStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int wifiStateExtra = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                    WifiManager.WIFI_STATE_UNKNOWN);
            String info  = "";
            switch (wifiStateExtra) {
                case WifiManager.WIFI_STATE_ENABLED:
                    info  = "WiFi is ON";
                    break;
                case WifiManager.WIFI_STATE_DISABLED:
                    info  = "WiFi is OFF";
                    break;
            }

         
        }
    };
728x90
반응형

'Android' 카테고리의 다른 글

Android _ Pixel GridView ( feat. Canvas )  (0) 2022.12.13
android EditText InputFilter  (0) 2022.10.25
Android Gradle ?? - Android 빌드시스템  (0) 2022.09.17
Android UI 파편화 관련  (0) 2022.09.01
android 조이스틱  (0) 2022.03.25