Example usage for android.net.wifi WifiManager SCAN_RESULTS_AVAILABLE_ACTION

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

Introduction

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

Prototype

String SCAN_RESULTS_AVAILABLE_ACTION

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

Click Source Link

Document

An access point scan has completed, and results are available.

Usage

From source file:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java

@Override
public void onStart() {

    super.onStart();

    if (mGoogleApiClient != null)
        mGoogleApiClient.connect();//from w  w  w.  jav a 2 s  . c o m

    // Registering the broadcast receivers
    //registerReceiver(bReceiver, new IntentFilter(Constants.RECEIVED_RESOURCES_UPDATE));

    registerReceiver(mConnReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

    registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

}

From source file:com.vonglasow.michael.satstat.ui.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    isStopped = false;//from w ww . jav a 2  s.com
    registerLocationProviders();
    sensorManager.registerListener(this, mOrSensor, iSensorRate);
    sensorManager.registerListener(this, mAccSensor, iSensorRate);
    sensorManager.registerListener(this, mGyroSensor, iSensorRate);
    sensorManager.registerListener(this, mMagSensor, iSensorRate);
    sensorManager.registerListener(this, mLightSensor, iSensorRate);
    sensorManager.registerListener(this, mProximitySensor, iSensorRate);
    sensorManager.registerListener(this, mPressureSensor, iSensorRate);
    sensorManager.registerListener(this, mHumiditySensor, iSensorRate);
    sensorManager.registerListener(this, mTempSensor, iSensorRate);
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
        registerPhoneStateListener();
    else
        permsRequested[Const.PERM_REQUEST_PHONE_STATE_LISTENER] = true;

    // register for certain WiFi events indicating that new networks may be in range
    // An access point scan has completed, and results are available.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

    // The state of Wi-Fi connectivity has changed.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));

    // The RSSI (signal strength) has changed.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));

    // A connection to the supplicant has been established or the connection to the supplicant has been lost.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION));

    permsRequested[Const.PERM_REQUEST_OFFLINE_MAP] = prefMapOffline;

    /*
     * Refresh map layers when offline map is selected and we have storage permission
     * (it might have been granted while we were gone, in which case we wouldn't have the layer)
     */
    if (prefMapOffline && (mapSectionFragment != null) && (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED))
        mapSectionFragment.onMapSourceChanged();

    requestPermissions();
}

From source file:org.sipdroid.sipua.ui.Receiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String intentAction = intent.getAction();
    if (!Sipdroid.on(context))
        return;/*from ww w. j a v  a 2s.  c  o  m*/
    if (!Sipdroid.release)
        Log.i("SipUA:", intentAction);
    if (mContext == null)
        mContext = context;
    if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {
        on_vpn(false);
        engine(context).register();
    } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)
            || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)
            || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)
            || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) {
        engine(context).register();
    } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) {
        String state = intent.getSerializableExtra("connection_state").toString();
        if (state != null && on_vpn() != state.equals("CONNECTED")) {
            on_vpn(state.equals("CONNECTED"));
            for (SipProvider sip_provider : engine(context).sip_providers)
                if (sip_provider != null)
                    sip_provider.haltConnections();
            engine(context).register();
        }
    } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) {
        engine(context).registerMore();
    } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED)
            && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) {
        stopRingtone();
        pstn_state = intent.getStringExtra("state");
        pstn_time = SystemClock.elapsedRealtime();
        if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE)
            broadcastCallStateChanged(null, null);
        if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL)
            mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000);
        else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL
                || call_state == UserAgent.UA_STATE_OUTGOING_CALL))
            mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000);
        else if (pstn_state.equals("IDLE")) {
            mHandler.removeMessages(MSG_HOLD);
            mHandler.removeMessages(MSG_HANGUP);
            if (call_state == UserAgent.UA_STATE_HOLD)
                mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000);
        }
    } else if (intentAction.equals(ACTION_DOCK_EVENT)) {
        docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7;
        if (call_state == UserAgent.UA_STATE_INCALL)
            engine(mContext).speaker(speakermode());
    } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) {
        bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1);
        progress();
        RtpStreamSender.changed = true;
    } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) {
        headset = intent.getIntExtra("state", -1);
        if (call_state == UserAgent.UA_STATE_INCALL)
            engine(mContext).speaker(speakermode());
    } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) {
        if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI))
            alarm(0, OwnWifi.class);
    } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) {
        mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000);
    } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) {
        if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) {
            WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wi = wm.getConnectionInfo();
            if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null
                    || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0)
                alarm(2 * 60, OwnWifi.class);
            else
                alarm(15 * 60, OwnWifi.class);
        }
        if (SipdroidEngine.pwl != null)
            for (PowerManager.WakeLock pwl : SipdroidEngine.pwl)
                if (pwl != null && pwl.isHeld()) {
                    pwl.release();
                    pwl.acquire();
                }
    } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI,
                org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI))
            mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000);
    } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
        if (SystemClock.uptimeMillis() > lastscan + 45000
                && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI,
                        org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) {
            WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wi = wm.getConnectionInfo();
            String activeSSID = null;
            if (wi != null)
                activeSSID = wi.getSSID();
            if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x")))
                activeSSID = null;
            List<ScanResult> mScanResults = wm.getScanResults();
            List<WifiConfiguration> configurations = wm.getConfiguredNetworks();
            if (configurations != null) {
                WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null;
                for (final WifiConfiguration config : configurations) {
                    if (maxconfig == null || config.priority > maxconfig.priority) {
                        maxconfig = config;
                    }
                    if (config.SSID != null
                            && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID)))
                        activeconfig = config;
                }
                ScanResult bestscan = null, activescan = null;
                if (mScanResults != null)
                    for (final ScanResult scan : mScanResults) {
                        for (final WifiConfiguration config : configurations) {
                            if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) {
                                if (bestscan == null || scan.level > bestscan.level) {
                                    bestscan = scan;
                                    bestconfig = config;
                                }
                                if (config == activeconfig)
                                    activescan = scan;
                            }
                        }
                    }
                if (activescan != null)
                    System.out.println("debug wifi asu(active)" + asu(activescan));
                if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority)
                        && asu(bestscan) > asu(activescan) * 1.5 &&
                        /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) {
                    if (!Sipdroid.release)
                        Log.i("SipUA:", "changing to " + bestconfig.SSID);
                    if (activeSSID == null || !activeSSID.equals(bestscan.SSID))
                        wm.disconnect();
                    bestconfig.priority = maxconfig.priority + 1;
                    wm.updateNetwork(bestconfig);
                    wm.enableNetwork(bestconfig.networkId, true);
                    wm.saveConfiguration();
                    if (activeSSID == null || !activeSSID.equals(bestscan.SSID))
                        wm.reconnect();
                    lastscan = SystemClock.uptimeMillis();
                } else if (activescan != null && asu(activescan) < 15) {
                    wm.disconnect();
                    wm.disableNetwork(activeconfig.networkId);
                    wm.saveConfiguration();
                }
            }
        }
    }
}

From source file:com.davidmascharka.lips.TrackerActivity.java

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

    File root = Environment.getExternalStorageDirectory();
    File dir = new File(root.getAbsolutePath() + "/indoor_localization");
    dir.mkdirs();/*from ww  w.ja v  a  2 s.c o m*/
    file = new File(dir, "livetest_" + building + ".txt");
    valuesFile = new File(dir, "livetest_" + building + "_values.txt");
    try {
        outputStream = new FileOutputStream(file, true);
        valuesOutputStream = new FileOutputStream(valuesFile, true);
        writer = new PrintWriter(outputStream);
        valuesWriter = new PrintWriter(valuesOutputStream);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Set building textview to the building the user has selected
    //TextView buildingText = (TextView) findViewById(R.id.text_building);
    //buildingText.setText("Building: " + building);

    // Set room size textview to the room size the user has selected
    //TextView roomSizeText = (TextView) findViewById(R.id.text_room_size);
    //roomSizeText.setText("Room size: " + roomWidth + " x " + roomLength);

    // Set grid options
    GridView grid = (GridView) findViewById(R.id.tracker_gridView);
    //grid.setGridSize(roomWidth, roomLength);
    grid.setGridSize(102, 64);
    grid.setCatchInput(false);
    //grid.setDisplayMap(displayMap);

    // Register to get sensor updates from all the available sensors
    sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : sensorList) {
        sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST);
    }

    // Enable wifi if it is disabled
    if (!wifiManager.isWifiEnabled()) {
        Toast.makeText(this, "WiFi not enabled. Enabling...", Toast.LENGTH_SHORT).show();
        wifiManager.setWifiEnabled(true);
    }

    // Request location updates from gps and the network
    //@author Mahesh Gaya added permission if-statment
    if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        Log.i(TAG, "Permissions have NOT been granted. Requesting permissions.");
        requestMyPermissions();
    } else {
        Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network");
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    }

    registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

    wifiManager.startScan();
    Toast.makeText(this, "Initiated scan", Toast.LENGTH_SHORT).show();

    xText = (TextView) findViewById(R.id.tracker_text_xcoord);
    yText = (TextView) findViewById(R.id.tracker_text_ycoord);
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    isStopped = false;//from w  w w.  j  a  v  a2 s  .  c  o m
    registerLocationProviders(this);
    mLocationManager.addGpsStatusListener(this);
    mSensorManager.registerListener(this, mOrSensor, iSensorRate);
    mSensorManager.registerListener(this, mAccSensor, iSensorRate);
    mSensorManager.registerListener(this, mGyroSensor, iSensorRate);
    mSensorManager.registerListener(this, mMagSensor, iSensorRate);
    mSensorManager.registerListener(this, mLightSensor, iSensorRate);
    mSensorManager.registerListener(this, mProximitySensor, iSensorRate);
    mSensorManager.registerListener(this, mPressureSensor, iSensorRate);
    mSensorManager.registerListener(this, mHumiditySensor, iSensorRate);
    mSensorManager.registerListener(this, mTempSensor, iSensorRate);
    mTelephonyManager.listen(mPhoneStateListener,
            (LISTEN_CELL_INFO | LISTEN_CELL_LOCATION | LISTEN_DATA_CONNECTION_STATE | LISTEN_SIGNAL_STRENGTHS));

    // register for certain WiFi events indicating that new networks may be in range
    // An access point scan has completed, and results are available.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

    // The state of Wi-Fi connectivity has changed.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));

    // The RSSI (signal strength) has changed.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));

    // A connection to the supplicant has been established or the connection to the supplicant has been lost.
    registerReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION));

    wifiTimehandler.postDelayed(wifiTimeRunnable, WIFI_REFRESH_DELAY);

    if ((isMapViewReady) && (mapDownloadLayer != null))
        mapDownloadLayer.onResume();
}