Example usage for android.net.wifi WifiManager WIFI_MODE_FULL

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

Introduction

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

Prototype

int WIFI_MODE_FULL

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

Click Source Link

Document

In this Wi-Fi lock mode, Wi-Fi will be kept active, and will behave normally, i.e., it will attempt to automatically establish a connection to a remembered access point that is within range, and will do periodic scans if there are remembered access points but none are in range.

Usage

From source file:Main.java

public static WifiManager.WifiLock createWifiLock(Context context, String tag) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    int lockType = WifiManager.WIFI_MODE_FULL;

    // Use WIFI_MODE_FULL_HIGH_PERF if API level 12 or higher.
    if (Build.VERSION.SDK_INT >= 12) {
        lockType = 3; // WifiManager.WIFI_MODE_FULL_HIGH_PERF
    }/*from  w w w .  j av  a  2s.c o m*/

    return wm.createWifiLock(lockType, tag);
}

From source file:Main.java

public static boolean acquireWifiLock(Context context) {
    //We only allow backup on wifi connection. Make sure we are connected and if so lock the wifi connection
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifi.isConnected()) {
        if (wifiLock == null) {
            WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "com.zns.comicdroid.wifilock");
            wifiLock.setReferenceCounted(true);
            wifiLock.acquire();/*from  www . java  2s  .co  m*/
        } else {
            wifiLock.acquire();
        }
        return true;
    }
    return false;
}

From source file:com.ilearnrw.reader.tasks.AddToLibraryTask.java

public void run(String... params) {

    wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wakeLock");

    wifiLock.acquire();/*from  w w w  . jav  a2 s.  c o  m*/
    wakeLock.acquire();
    this.execute(params);
}

From source file:org.opensilk.music.cast.CastWebServer.java

public CastWebServer(Context context, String host, int port) {
    super(host, port);
    mContext = context;/*www .java  2  s . c  om*/
    // get the lock
    mWifiLock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "CastServer");
    mWifiLock.setReferenceCounted(false);
    // arbitrary size might increase as needed;
    mEtagCache = new LruCache<>(20);
    mBytePool = new ByteArrayPool(2 * 1024 * 1024);
}

From source file:cz.babi.android.remoteme.service.ConnectionService.java

@Override
public void onCreate() {
    if (Common.DEBUG)
        Log.d(TAG_CLASS_NAME, "[onCreate]");

    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    /* Lock Wi-Fi, if need so. */
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "WiFiLockTag");
    if (preferences.getBoolean(getString(R.string.pref_name_keep_wifi_alive), true))
        lockWiFi();/* w w w .  ja  v a2 s.  com*/

    /* Display a notification about us starting. */
    if (preferences.getBoolean(getString(R.string.pref_name_show_notification), true)) {
        showNotification();
    }
}

From source file:com.smedic.tubtub.BackgroundAudioService.java

@Override
public void onCreate() {
    super.onCreate();
    videoItem = new YouTubeVideo();

    network = new NetworkConf(getApplicationContext());

    mWifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "tub_wifi_lock");

    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setOnErrorListener(this);

    initMediaSessions();//  w w  w.  j  a  v a2  s  .c  o  m
    initPhoneCallListener();
}

From source file:app.wz.MainActivity.java

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

    self = this;/*from  w  w  w  .  j  a  v a2 s  . c  o  m*/

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setProgressBarIndeterminateVisibility(false);

    setContentView(R.layout.layout_main);

    // initialize your android device sensor capabilities
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");

    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    lock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "LockTag");

    prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());

    textScroll = (ScrollView) findViewById(R.id.textScroll);
    textRead = (TextView) findViewById(R.id.textRead);

    commStatus = (TextView) findViewById(R.id.commStatus);
    pingStatus = (TextView) findViewById(R.id.pingStatus);
    inputCmd = (EditText) findViewById(R.id.inputCmd);
    inputVal = (EditText) findViewById(R.id.inputVal);

    gb = (GlobalApp) getApplication();

    gb.bt = new BluetoothSPP(this);
    bt = gb.bt;
    gb.arduino = new ArduinoFirmata(this, bt);
    arduino = gb.arduino;

    gb.neuro = new NeuroInterface(prefs, gb);

    neuro = gb.neuro;

    if (prefs.getBoolean("autoload", false)) {
        if (neuro.loadWeights(prefs.getString("last_save", ""))) {
            textRead.append("Restored Weights at Step " + neuro.count + "\n");
            textScroll.fullScroll(View.FOCUS_DOWN);
        }
    }

    if (!bt.isBluetoothAvailable()) {
        Toast.makeText(getApplicationContext(), "Bluetooth is not available", Toast.LENGTH_SHORT).show();
        finish();
    }

    bt.setOnDataReceivedListener(new OnDataReceivedListener() {
        public void onDataReceived(byte[] data, String message) {
            gb.lastResponseBT = System.currentTimeMillis();
            arduino.processInput(data);
        }
    });

    bt.setBluetoothConnectionListener(new BluetoothConnectionListener() {
        public void onDeviceDisconnected() {

            haltNeuro();

            commStatus.setText("Status : Not Connected");
            menu.clear();
            getMenuInflater().inflate(R.menu.connection, menu);
        }

        public void onDeviceConnectionFailed() {
            commStatus.setText("Status : Connection Failed");
        }

        public void onDeviceConnected(String name, String address) {
            commStatus.setText("Status : Connected to " + name);
            menu.clear();
            getMenuInflater().inflate(R.menu.disconnection, menu);
        }
    });

    //        bt.setAutoConnectionListener(new BluetoothSPP.AutoConnectionListener() {
    //            public void onNewConnection(String name, String address) {
    //                Log.i("Check", "New Connection - " + name + " - " + address);
    //            }
    //
    //            public void onAutoConnectionStarted() {
    //                Log.i("Check", "Auto connection started");
    //            }
    //        });

    if (!bt.isBluetoothEnabled()) {
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(intent, BluetoothState.REQUEST_ENABLE_BT);
    } else {
        if (!bt.isServiceAvailable()) {
            bt.setupService();
            bt.startService(BluetoothState.DEVICE_ANDROID);
            setup();
        }
    }

    refreshPing.start();
    neuroThread.start();

    new Thread() {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (neuro.count > neuro.lastDisplay) {
                    neuro.lastDisplay = neuro.count;
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (!neuro.halt) {
                                textRead.append(
                                        "P err:  " + (new DecimalFormat("0.000E0")).format(neuro.avg_error)
                                                + "    O err:  "
                                                + (new DecimalFormat("0.000E0")).format(neuro.avg_obj_error)
                                                + "    stp:  " + neuro.count + "\n");

                                textScroll.fullScroll(View.FOCUS_DOWN);
                            }
                        }
                    });
                }
            }
        }
    }.start();

    new Thread() {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (textRead.length() > 20000)
                            textRead.setText("");
                    }
                });
            }
        }
    }.start();

}

From source file:info.tongrenlu.music.LocalPlayback.java

public LocalPlayback(MusicService service) {
    this.mService = service;
    this.mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE);
    // Create the Wifi lock (this does not acquire the lock, this just creates it)
    this.mWifiLock = ((WifiManager) service.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, MusicService.TAG);
}

From source file:com.classiqo.nativeandroid_32bitz.playback.LocalPlayback.java

public LocalPlayback(Context context, MusicProvider musicProvider) {
    this.mContext = context;
    this.mMusicProvider = musicProvider;
    this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "nA_32bitz_lock");
    this.mState = PlaybackStateCompat.STATE_NONE;
}

From source file:net.simno.klingar.playback.LocalPlayback.java

LocalPlayback(Context context, MusicController musicController, AudioManager audioManager,
        WifiManager wifiManager) {//from  w w w. jav a  2 s  . c  om
    this.context = context;
    this.musicController = musicController;
    this.audioManager = audioManager;
    this.wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "klingar_lock");
    this.state = PlaybackStateCompat.STATE_NONE;
    String agent = Util.getUserAgent(context, context.getResources().getString(R.string.app_name));
    this.dataSourceFactory = new DefaultDataSourceFactory(context, agent, null);
    this.extractorsFactory = new DefaultExtractorsFactory();
}