List of usage examples for android.bluetooth BluetoothAdapter getBluetoothLeScanner
public BluetoothLeScanner getBluetoothLeScanner()
From source file:Main.java
public static Pair<BluetoothManager, BluetoothAdapter> checkBT(final Activity activity) { // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!btleSupport(activity)) { return null; }/*w w w.j a v a2 s. c o m*/ final BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); //On some devices this does not work try { bluetoothAdapter.getBluetoothLeScanner(); } catch (NoSuchMethodError e) { return null; } // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, 1); bluetoothAdapter = bluetoothManager.getAdapter(); } return new Pair<BluetoothManager, BluetoothAdapter>(bluetoothManager, bluetoothAdapter); }
From source file:com.google.sample.beaconservice.MainActivityFragment.java
private void createScanner() { BluetoothManager btManager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter btAdapter = btManager.getAdapter(); if (btAdapter == null || !btAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, Constants.REQUEST_CODE_ENABLE_BLE); }//www .j av a2s . c o m if (btAdapter == null || !btAdapter.isEnabled()) { Log.e(TAG, "Can't enable Bluetooth"); Toast.makeText(getActivity(), "Can't enable Bluetooth", Toast.LENGTH_SHORT).show(); return; } scanner = btAdapter.getBluetoothLeScanner(); }
From source file:com.juce.jucedemo.JuceDemo.java
public BluetoothManager getAndroidBluetoothManager() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter == null) return null; if (adapter.getBluetoothLeScanner() == null) return null; synchronized (JuceDemo.class) { if (bluetoothManager == null) bluetoothManager = new BluetoothManager(); }/*from www . j av a2s .c om*/ return bluetoothManager; }