public void enable() { db("enable Bluetooth"); if (!isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }
public void setName(String name) { if (bluetoothAdapter.setName(name)) { System.out.println("B4Manager: name changed"); activity.toast("name changed"); } else System.out.println("B4Manager: name not changed"); deviceName = name; }
public BLEManager(MainActivity activity) { this.activity = activity; isScanning = false; isAdvertising = false; deviceName = "device1337"; bluetoothManager = (android.bluetooth.BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null) try { throw new Exception("Turn on Bluetooth dickhead"); } catch (Exception e) { System.err.println("Could not throw exception"); } System.out.println("Bluetooth LE manager created"); System.out.println( " multiple advertisement: " + bluetoothAdapter.isMultipleAdvertisementSupported()); }
public void makeDiscoverable() { System.out.println("make discoverable"); Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120); activity.startActivity(discoverableIntent); }