예제 #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);
 }