Пример #1
0
 public void enable() {
   db("enable Bluetooth");
   if (!isEnabled()) {
     Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
     activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
   }
 }
Пример #2
0
  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;
  }
Пример #3
0
  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());
  }
Пример #4
0
 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);
 }