get Rfcomm Socket By Reflection - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth

Description

get Rfcomm Socket By Reflection

Demo Code

import java.lang.reflect.Method;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;

public class Main {

  private static synchronized BluetoothSocket getRfcommSocketByReflection(BluetoothDevice device) throws Exception {
    if (device == null)
      return null;
    Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });

    return (BluetoothSocket) m.invoke(device, 1);
  }//  w  ww.ja v  a2 s  .c o m

}

Related Tutorials