get Insecure Rfcomm Socket By Reflection - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth

Description

get Insecure Rfcomm Socket By Reflection

Demo Code

import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothSocket;
import android.os.Build;
import java.lang.reflect.Method;
import java.util.UUID;

public class Main{

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

        return (BluetoothSocket) m.invoke(device, 1);
    }//from  w  w  w.java2 s  . co m

}

Related Tutorials