connect to a Bluetooth Device - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth

Description

connect to a Bluetooth Device

Demo Code

import java.lang.reflect.Method;

import android.bluetooth.BluetoothDevice;

public class Main {

  @SuppressWarnings({ "unchecked", "rawtypes", "unused" })
  public static Boolean connect(BluetoothDevice bdDevice) {
    Boolean bool = false;/*from  w  w  w.  ja  v a  2s.c  o  m*/
    try {
      Class cl = Class.forName("android.bluetooth.BluetoothDevice");
      Class[] par = {};
      Method method = cl.getMethod("createBond", par);
      Object[] args = {};
      bool = (Boolean) method.invoke(bdDevice);// , args);// this invoke creates the detected devices paired.
    } catch (Exception e) {
      e.printStackTrace();
    }
    return bool.booleanValue();
  }

}

Related Tutorials