Example usage for android.net.wifi WifiManager WIFI_STATE_CHANGED_ACTION

List of usage examples for android.net.wifi WifiManager WIFI_STATE_CHANGED_ACTION

Introduction

In this page you can find the example usage for android.net.wifi WifiManager WIFI_STATE_CHANGED_ACTION.

Prototype

String WIFI_STATE_CHANGED_ACTION

To view the source code for android.net.wifi WifiManager WIFI_STATE_CHANGED_ACTION.

Click Source Link

Document

Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown.

Usage

From source file:uk.ac.horizon.ubihelper.service.channel.WifiScannerChannel.java

/**
 * @param handler//from  ww  w . j  a  v a  2s .  c  om
 * @param name
 */
public WifiScannerChannel(Service service, Handler handler, String name) {
    super(handler, name);
    wifi = (WifiManager) service.getSystemService(Service.WIFI_SERVICE);
    this.service = service;
    if (wifi == null)
        Log.w(TAG, "No WifiManager");
    IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    this.service.registerReceiver(receiver, filter);
}

From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    //   Log.e(this.getClass().getSimpleName(), "onReceive(): " + action);

    updateWifiViews = true;// w  w w .  java2 s. com

    wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiState = wifiManager.getWifiState();
    wifiInfo = wifiManager.getConnectionInfo();

    if ((wifiState == WifiManager.WIFI_STATE_ENABLED) && (wifiInfo.getIpAddress() == 0))
        detailedState = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());

    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        if (isConnectionReady(intent)) {
            String securityString = WifiUtils.getSecurityString(context, wifiManager, wifiInfo.getBSSID());
            NetworkStateService.setWifiSecurityString(securityString);
            detailsString = context.getString(R.string.security) + ": " + securityString;

            Intent serviceIntent = new Intent(context, NetworkStateService.class);
            serviceIntent.setAction(Constants.ACTION_WIFI_CONNECTED);
            context.startService(serviceIntent);
        }

        partiallyUpdateWidgets(context);
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)
            || Constants.ACTION_WIFI_SCANNING.equals(action)) {
        partiallyUpdateWidgets(context);
    } else if (Intent.ACTION_SCREEN_ON.equals(action) || Constants.ACTION_WIFI_LINK_SPEED.equals(action)) {
        if (isConnected()) {
            setDetailsString(context);
            partiallyUpdateWidgets(context);
        }
    } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) {
        if (isConnected())
            setDetailsString(context);

        partiallyUpdateWidget(context, AppWidgetManager.getInstance(context),
                intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
    }
}

From source file:sssemil.com.wifiapmanager.MainService.java

@Override
public void onCreate() {
    super.onCreate();

    mContext = this;

    IntentFilter intentFilter = new IntentFilter("android.net.wifi.WIFI_AP_STATE_CHANGED");
    intentFilter.addAction("android.net.conn.TETHER_STATE_CHANGED");
    intentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

    mIcon = R.drawable.ic_tt;//from  w  w w . ja  v  a  2 s  .c o  m

    mContext.registerReceiver(mReceiver, intentFilter);

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);

    mLooper = getMainLooper();
    mScanThread = new HandlerThread("WifiClientScanner");
    if (!mScanThread.isAlive()) {
        mScanThread.start();
        mScanHandler = new WifiClientScanner(mScanThread.getLooper());
        mScanHandler.sendEmptyMessage(0);
    }
}

From source file:net.helff.wificonnector.WifiConnectivityReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "action: " + intent.getAction());

    if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {

        Intent locationIntent = new LocationIntent();
        context.sendBroadcast(locationIntent);
    }//from   w w w  .  ja  va2  s .  c  om

    if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {

        NetworkInfo networkInfo = (NetworkInfo) intent
                .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

        Log.d(TAG, "got network_state_changed with detailed info: " + networkInfo == null ? "nothing"
                : networkInfo.getDetailedState().name());

        if (networkInfo != null && networkInfo.isConnected()
                && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean autoConnect = prefs.getBoolean("autoConnect", false);

            Log.d(TAG, "triggering WifiConnectivityService with autoConnect=" + autoConnect);

            int command = autoConnect ? WifiConnectivityService.COMMAND_AUTO_UNLOCK_CONNECTION
                    : WifiConnectivityService.COMMAND_CHECK_CONNECTION;
            Intent msgIntent = new Intent(context, WifiConnectivityService.class);
            msgIntent.putExtra(WifiConnectivityService.INTENT_COMMAND, command);
            context.startService(msgIntent);
        }

    }
    if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        Log.d(TAG, "triggering WifiConnectivityService state changed");

        Intent msgIntent = new Intent(context, WifiConnectivityService.class);
        msgIntent.putExtra(WifiConnectivityService.INTENT_COMMAND,
                WifiConnectivityService.COMMAND_REFRESH_STATUS);
        context.startService(msgIntent);
    }
}

From source file:org.deviceconnect.android.deviceplugin.theta.activity.ThetaDeviceActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDeviceMgr = getDeviceManager();//w  w w  .jav  a  2  s.  c o m
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_LIST);
    if (fragment == null) {
        fragment = ThetaGalleryFragment.newInstance(mDeviceMgr);
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(android.R.id.content, fragment, TAG_LIST);
        ft.commit();
    }
    mListener = getDeviceManager();
    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    registerReceiver(mWifiReceiver, filter);
}

From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.WifiScanner.java

public void onReceive(Context c, Intent intent) {
    String action = intent.getAction();

    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        if (isScanEnabled()) {
            activatePeriodicScan(ActiveOrPassiveStumbling.ACTIVE_STUMBLING);
        } else {//from  ww w  .  j a  v  a 2 s  . c  o  m
            deactivatePeriodicScan();
        }
    } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {
        final List<ScanResult> scanResultList = getScanResults();
        if (scanResultList == null) {
            return;
        }
        final ArrayList<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (ScanResult scanResult : scanResultList) {
            scanResult.BSSID = BSSIDBlockList.canonicalizeBSSID(scanResult.BSSID);

            if (shouldLog(scanResult)) {
                // Once we've checked that we want this scan result, we can safely discard
                // the SSID and capabilities.
                scanResult.SSID = "";
                scanResult.capabilities = "";
                scanResults.add(scanResult);
            }
        }
        mVisibleAPs.set(scanResults.size());
        reportScanResults(scanResults);
    }
}

From source file:org.wahtod.wififixer.ui.LocalNetworksLoader.java

private void registerReceiver() {
    IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    BroadcastHelper.registerReceiver(getContext(), receiver, filter, false);
}

From source file:com.google.android.gms.samples.vision.face.facetracker.MainActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//  ww w  .j ava  2  s  . c om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainactivity);

    //        ---Ambil username dari sharedpreference agar user tetap dapat melihat schedule jika keluar dari apps------
    sharedPreferences = getSharedPreferences("PHAROS", MODE_PRIVATE);
    username = sharedPreferences.getString("Username", "");
    //        ---------------------------------------------------------------------------------------------------------

    //        ---Deklarasi fragment fragment yang akan di gunakan---
    Fragment CameraFragment = new CameraFragment();
    Fragment LoginFramgent = new LoginFragment();
    Fragment ScheduleFragment = new ScheduleFragment();
    //        -----------------------------------------------------

    //        Meminta permisssion untuk GPS jika menggunakan android Marshmallow keatas
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(
            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, 1);
    }
    //        -------------------------------------------------------------------------

    //       ------- Instantiasi intent filter untuk broadcast recevier------
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

    IntentFilter connectionIntentFilter = new IntentFilter();
    connectionIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    //        ---------------------------------------------------------------------

    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiConfiguration = new WifiConfiguration();

    //        Registrasikan broadcast receiver
    registerReceiver(new wifiEnabled(wifiManager), intentFilter);
    registerReceiver(new wifiConnecting(wifiManager), connectionIntentFilter);
    //        ---------------------------------------

    //       -------- Deklarasi view pager---------
    viewPager = (ViewPager) findViewById(R.id.fragmentFrame);
    pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), CameraFragment, LoginFramgent,
            ScheduleFragment);
    viewPager.setAdapter(pagerAdapter);
    //        Mengarahkan halaman awal saat membuka aplikasi ke fragment index 1
    viewPager.setCurrentItem(1);
    //        -------------------------------------

}

From source file:org.peterbaldwin.vlcremote.app.PickServerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PickServerFragment fragment = findOrReplaceFragment(android.R.id.content, TAG, PickServerFragment.class);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    mPort = getIntent().getIntExtra(PortSweeper.EXTRA_PORT, 0);
    if (mPort == 0) {
        throw new IllegalArgumentException("Port must be specified");
    }//from  w  ww.  ja  va 2 s .com

    mFile = getIntent().getStringExtra(PortSweeper.EXTRA_FILE);
    if (mFile == null) {
        throw new IllegalArgumentException("File must be specified");
    }

    mWorkers = getIntent().getIntExtra(PortSweeper.EXTRA_WORKERS, DEFAULT_WORKERS);

    mPortSweeper = createPortSweeper(fragment);
    startSweep();

    // Registering the receiver triggers a broadcast with the initial state.
    // To tell the difference between a broadcast triggered by registering a
    // receiver and a broadcast triggered by a true network event, note the
    // time and ignore all broadcasts for one second.
    mCreateTime = SystemClock.uptimeMillis();

    mReceiver = new MyBroadcastReceiver();

    // For robustness, update the connection status for all types of events.
    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    registerReceiver(mReceiver, filter);
}

From source file:com.geniatech.client_phone.wifi.WifiStatusTest.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

    mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    mWifiStateFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

    registerReceiver(mWifiStateReceiver, mWifiStateFilter);

    setContentView(R.layout.wifi_status_test);

    updateButton = (Button) findViewById(R.id.update);
    updateButton.setOnClickListener(updateButtonHandler);

    mWifiState = (TextView) findViewById(R.id.wifi_state);
    mNetworkState = (TextView) findViewById(R.id.network_state);
    mSupplicantState = (TextView) findViewById(R.id.supplicant_state);
    mRSSI = (TextView) findViewById(R.id.rssi);
    mBSSID = (TextView) findViewById(R.id.bssid);
    mSSID = (TextView) findViewById(R.id.ssid);
    mHiddenSSID = (TextView) findViewById(R.id.hidden_ssid);
    mIPAddr = (TextView) findViewById(R.id.ipaddr);
    mMACAddr = (TextView) findViewById(R.id.macaddr);
    mNetworkId = (TextView) findViewById(R.id.networkid);
    mLinkSpeed = (TextView) findViewById(R.id.link_speed);
    mScanList = (TextView) findViewById(R.id.scan_list);

}