Example usage for android.bluetooth BluetoothAdapter stopLeScan

List of usage examples for android.bluetooth BluetoothAdapter stopLeScan

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter stopLeScan.

Prototype

@Deprecated
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public void stopLeScan(LeScanCallback callback) 

Source Link

Document

Stops an ongoing Bluetooth LE device scan.

Usage

From source file:com.orange.beaconme_sdk.ble.control.BLEDeviceScanner.java

private void stopScanning() {
    stopReScanTimer();/* w  ww. ja va  2 s .  c om*/
    BluetoothAdapter bluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE))
            .getAdapter();
    if (bluetoothAdapter != null) {
        try {
            bluetoothAdapter.stopLeScan(mScanCallback);
        } catch (NullPointerException ex) {
            //prevent OBGM-215 issue. For proper fix more information needed
        }
    }
    getDeviceManager().clear();
}

From source file:com.evothings.BLE.java

private void stopScan(final CordovaArgs args, final CallbackContext callbackContext) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    adapter.stopLeScan(this);
    mScanCallbackContext = null;/*from www.ja v  a  2 s .  c  o  m*/
}

From source file:com.evothings.BLE.java

/**
* Called when the WebView does a top-level navigation or refreshes.
*
* Plugins should stop any long-running processes and clean up internal state.
*
* Does nothing by default.//  w  ww.  j  ava2 s.  c o m
*
* Our version should stop any ongoing scan, and close any existing connections.
*/
@Override
public void onReset() {
    if (mScanCallbackContext != null) {
        BluetoothAdapter a = BluetoothAdapter.getDefaultAdapter();
        a.stopLeScan(this);
        mScanCallbackContext = null;
    }
    if (mGatt != null) {
        Iterator<GattHandler> itr = mGatt.values().iterator();
        while (itr.hasNext()) {
            GattHandler gh = itr.next();
            if (gh.mGatt != null)
                gh.mGatt.close();
        }
        mGatt.clear();
    }
}

From source file:com.evothings.BLE.java

private void reset(final CordovaArgs args, final CallbackContext cc) throws JSONException {
    mResetCallbackContext = null;//from   w ww  .j  av a  2s  . c  om
    BluetoothAdapter a = BluetoothAdapter.getDefaultAdapter();
    if (mScanCallbackContext != null) {
        a.stopLeScan(this);
        mScanCallbackContext = null;
    }
    int state = a.getState();
    //STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF.
    if (state == BluetoothAdapter.STATE_TURNING_ON) {
        // reset in progress; wait for STATE_ON.
        mResetCallbackContext = cc;
        return;
    }
    if (state == BluetoothAdapter.STATE_TURNING_OFF) {
        // reset in progress; wait for STATE_OFF.
        mResetCallbackContext = cc;
        return;
    }
    if (state == BluetoothAdapter.STATE_OFF) {
        boolean res = a.enable();
        if (res) {
            mResetCallbackContext = cc;
        } else {
            cc.error("enable");
        }
        return;
    }
    if (state == BluetoothAdapter.STATE_ON) {
        boolean res = a.disable();
        if (res) {
            mResetCallbackContext = cc;
        } else {
            cc.error("disable");
        }
        return;
    }
    cc.error("Unknown state: " + state);
}

From source file:com.mooshim.mooshimeter.main.ScanActivity.java

public synchronized void startScan() {
    if (mScanOngoing)
        return;//from  w  w w.  j  a va2 s  . c  o  m
    mScanOngoing = true;

    final Handler h = new Handler();
    mBtnScan.setEnabled(false);
    updateScanningButton(false);
    // Prune disconnected meters
    List<MooshimeterDevice> remove = new ArrayList<MooshimeterDevice>();
    for (MooshimeterDevice m : mMeterList) {
        if (m.mConnectionState == BluetoothProfile.STATE_DISCONNECTED) {
            remove.add(m);
        }
    }
    for (MooshimeterDevice m : remove) {
        mDeviceScrollView.removeView(mTileList.remove(mMeterList.indexOf(m)));
        mMeterList.remove(m);
        mMeterDict.remove(m.getAddress());
    }
    refreshAllMeterTiles();

    final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!bluetoothAdapter.startLeScan(mLeScanCallback)) {
        // Starting the scan failed!
        Log.e(TAG, "Failed to start BLE Scan");
        setError("Failed to start scan");
    }
    h.postDelayed(new Runnable() {
        @Override
        public void run() {
            mBtnScan.setEnabled(true);
            updateScanningButton(false);
            final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            bluetoothAdapter.stopLeScan(mLeScanCallback);
            mScanOngoing = false;
        }
    }, 5000);
}

From source file:net.emilymaier.movebot.HeartFragment.java

@Override
@SuppressWarnings("deprecation")
public void onClick(View view) {
    Log.d("HeartFragment", "Scan button clicked");
    final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        new NoBluetoothDialogFragment().show(act.getSupportFragmentManager(), "bluetooth");
        return;/*  w w w .j  av a 2s.c o  m*/
    }
    if (!bluetoothAdapter.isEnabled()) {
        new BluetoothDisabledDialogFragment().show(act.getSupportFragmentManager(), "disabled");
        return;
    }
    if (!act.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        new NoLeDialogFragment().show(act.getSupportFragmentManager(), "le");
        return;
    }
    Log.d("HeartFragment", "Starting scan");
    heartScan.setClickable(false);
    heartScan.setText("Scanning...");
    for (HeartDevice device : heartDevices) {
        device.bluetoothGatt.disconnect();
        device.bluetoothGatt.close();
    }
    heartDevices.clear();
    heartListAdapter.notifyDataSetChanged();
    bluetoothAdapter.startLeScan(new UUID[] { UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb") }, this);
    final HeartFragment t = this;
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Log.d("HeartFragment", "Stopping scan");
            bluetoothAdapter.stopLeScan(t);
            heartScan.setText("Scan");
            heartScan.setClickable(true);
            heartListAdapter.notifyDataSetChanged();
        }
    }, 5000);
}