Example usage for android.net.wifi WifiManager WIFI_MODE_SCAN_ONLY

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

Introduction

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

Prototype

int WIFI_MODE_SCAN_ONLY

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

Click Source Link

Document

In this Wi-Fi lock mode, Wi-Fi will be kept active, but the only operation that will be supported is initiation of scans, and the subsequent reporting of scan results.

Usage

From source file:fr.inria.ucn.Helpers.java

/**
 * Acquire the wifi wakelock.//from  w ww.  j a va 2 s  . co  m
 * @param c
 */
public static synchronized void acquireWifiLock(Context c) {
    WifiManager mgr = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    if (wifilock == null) {
        wifilock = mgr.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "ucn");
        wifilock.setReferenceCounted(false);
    }
    Log.d(Constants.LOGTAG, "acquire wifilock");
    wifilock.acquire();
    acquireLock(c);
}

From source file:csic.ceab.movelab.beepath.FixGet.java

/**
 * Creates a new FixGet service instance.<br>
 * Begins location recording process. Creates a location manager and two
 * location listeners. Begins requesting updates from both the GPS and
 * network services, with one location listener receiving updates from one
 * provider./*from   w ww . ja v  a2  s  .  co m*/
 * <p>
 * If either provider is unavailable, no updates will ever be returned to
 * the corresponding location listener.
 */

@Override
public void onCreate() {

    Context context = getApplicationContext();

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).createWifiLock(
            WifiManager.WIFI_MODE_SCAN_ONLY,
            context.getResources().getString(R.string.internal_message_id) + "WifiLock");

    wakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).newWakeLock(
            PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            context.getResources().getString(R.string.internal_message_id) + "ScreenDimWakeLock");

    minDist = Util.getMinDist(context);

}

From source file:org.ohmage.reminders.types.location.LocTrigService.java

@Override
public void onCreate() {
    //Let the service live forever
    setKeepAliveAlarm(this);

    //Cache the locations
    mLocList = new LinkedList<LocListItem>();
    populateLocList();/*from  ww w.  j a va 2s . c  o m*/

    initState();

    PowerManager powerMan = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);

    if (LocTrigConfig.useNetworkLocation) {
        Log.v(TAG, "LocTrigService: Using network location");
        WifiManager wifiMan = (WifiManager) getSystemService(WIFI_SERVICE);
        mWifiLock = wifiMan.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, TAG);
    }

    if (LocTrigConfig.useMotionDetection) {
        Log.v(TAG, "LocTrigService: Using motion detection");
    }

    mMotionDetectCB = new ILocationChangedCallback.Stub() {

        @Override
        public void locationChanged() throws RemoteException {
            if (LocTrigConfig.useMotionDetection) {
                mHandler.sendMessage(mHandler.obtainMessage());
            }

        }
    };

    mSamplingStarted = false;

    super.onCreate();
}

From source file:org.ohmage.triggers.types.location.LocTrigService.java

@Override
public void onCreate() {
    Log.i(DEBUG_TAG, "LocTrigService: onCreate");

    //Let the service live forever
    setKeepAliveAlarm();/*from   ww w.  j a va  2 s .  co m*/

    //Cache the locations
    mLocList = new LinkedList<LocListItem>();
    populateLocList();

    initState();

    PowerManager powerMan = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);

    if (LocTrigConfig.useNetworkLocation) {
        Log.i(DEBUG_TAG, "LocTrigService: Using network location");
        WifiManager wifiMan = (WifiManager) getSystemService(WIFI_SERVICE);
        mWifiLock = wifiMan.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, DEBUG_TAG);
    }

    if (LocTrigConfig.useMotionDetection) {
        Log.i(DEBUG_TAG, "LocTrigService: Using motion detection");
    }

    mMotionDetectCB = new ILocationChangedCallback.Stub() {

        @Override
        public void locationChanged() throws RemoteException {
            if (LocTrigConfig.useMotionDetection) {
                mHandler.sendMessage(mHandler.obtainMessage());
            }

        }
    };

    mSamplingStarted = false;

    super.onCreate();
}

From source file:com.putlocker.upload.DownloadService.java

@Override
protected void onHandleIntent(Intent intent) {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Download Wakelock");
    wl.acquire();/*from w  w w  .  ja va2  s.  co m*/

    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    WifiLock wifiLock = null;
    // We only want to aquire the wifi wake lock
    if (mWifi.isConnected()) {
        wifiLock = ((WifiManager) this.getSystemService(Context.WIFI_SERVICE))
                .createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "WlanSilencerScanLock");
        wifiLock.acquire();
    }

    if (intent.hasExtra(JOB_EXTRA_DOWNLOAD)) {
        handleDownloadIntent(intent);
    } else {
        handleUploadIntent(intent);
    }

    if (wifiLock != null && wifiLock.isHeld()) {
        wifiLock.release();
    }

    wl.release();
}