Java 类android.net.wifi.WifiManager.WifiLock 实例源码

项目:Stdy__Android    文件:MusicActivity.java   
public void setwifilock() {
    WifiLock wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");
    if (wifiLock.isHeld()){
        wifiLock.release();
    }
    else {
        wifiLock.acquire();
    }
}
项目:battleclient-android    文件:ShowEmails.java   
@Override
protected Void doInBackground(Void... params) {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sync_all_cpu");       
    wl.acquire();

    WifiLock wfl = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "sync_all_wifi");
    wfl.acquire();

    Message[] msgs = service.getAllMessagesArray();
    d.setMax(msgs.length);
    d.setProgress(0);

    for (Message m : msgs) {
        service.storeSingleMessageOnDatabase(m);
        try {
            publishProgress(m.getFrom()[0].toString() + ": " + m.getSubject());
        } catch (MessagingException e) {
            Log.e("ERROR", e.getMessage());
        }
    }

    wl.release();
    wfl.release();

    return null;
}
项目:AndroidPirateBox    文件:PirateBoxService.java   
@Override
public WifiLock getWifiLock() {
    return super.getWifiLock();
}
项目:persontracker    文件:UpdaterRestartDroneCommand.java   
@Override
public void execute(Context service) 
{
       delegate.setRestartingDroneState(IndicatorState.ACTIVE, 0, "");

    WifiManager wifi = (WifiManager) context.getContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifi.getConnectionInfo();

    ssid = wifiInfo.getSSID();
    context.setDroneNetworkSSID(ssid);
    droneRestarted = false;

    Log.d(getCommandName(), "Current connection ssid: " + ssid);

    // We need this in order to prevent disconnection due to device inactivity
    WifiLock lock = wifi.createWifiLock("DRONE_RESTART_LOCK");
    lock.acquire();

    if (context.getDroneFirmwareVersion().startsWith("2.")) {
        if (!TelnetUtils.executeRemotely(DroneConfig.getHost(), DroneConfig.TELNET_PORT, "reboot\n")) {
            delegate.setRestartingDroneState(IndicatorState.ACTIVE, 0, context.getContext().getString(R.string.update_file_sent_successfully_please_restart_drone));
        }
    } else {
        delegate.setRestartingDroneState(IndicatorState.ACTIVE, 0, context.getContext().getString(R.string.update_file_sent_successfully_please_restart_drone));
    }

    while (!context.isShuttingDown()) {

        if (!droneRestarted) {  
            if (FTPUtils.downloadFile(service, DroneConfig.getHost(), DroneConfig.getFtpPort(), "version.txt") == null) {
                droneRestarted = true;
                Log.d(getCommandName(), "Wifi signal lost. Marking as restarted");
                onSuccess();
                break;
            } else {
                Log.d(getCommandName(), "Wifi still enabled");
            }
        } 


        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
            break;
        }

        Log.d(getCommandName(), "Checking connection...");
    }

    lock.release();
}
项目:RHome    文件:WifiHelper.java   
public WifiLock getNewWifiLock(String lock_postfix) {
    return mManager.createWifiLock(WifiManager.WIFI_MODE_FULL, WIFI_LOCK_TAG + lock_postfix);
}
项目:simlar-android    文件:SimlarService.java   
private WifiLock createWifiWakeLock()
{
    return ((WifiManager) Util.getSystemService(this, Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "SimlarWifiLock");
}