On Oct 7, 2011, at 7:38 PM, [email protected] wrote:
> I'm trying to create a Bluetooth  socket using 
> 'createRFcommSocketToServiceRecord' with some problems. Now, I've read that  
> the createRFcommSocketToServiceRecord method is not working in Android 
> 2.1/2.2. The workaround I saw is the following Android code but I don't know 
> how to adapt to Monodroid: 
> 
> BluetoothDevice device;
> Method m = device.getClass().getMethod("createRfcommSocket", new 
> Class[]{int.class});
> BluetoothSocket tmp = (BluetoothSocket)m.invoke(device, Integer.valueOf(1));

This is using Java Reflection, which we don't expose. However, we do expose JNI 
[0], which allows the same functionality with a different syntax:

        IntPtr createRfcommSocket = JNIEnv.GetMethodID(
                        device.Class.Handle,
                        "createRfcommSocket",
                        "(I)Landroid/bluetooth/BluetoothSocket;");
        IntPtr socket = JNIEnv.CallObjectMethod(
                        device.Handle,
                        createRfcommSocket,
                        new JValue (1));
        // `socket` now holds a BluetoothSocket instance; do something with 
it...

 - Jon

[0] http://docs.mono-android.net/index.aspx?link=T%3aAndroid.Runtime.JNIEnv

_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to