Thanks,

I just found the work-around (hack) before I got your reply and it seems to
work fine.

Thanks again, 


Steve Sharrock
Architecture/Design/Programming
www.sharkcode.com

-----Original Message-----
From: Jonathan Pryor [mailto:[email protected]] 
Sent: Wednesday, September 19, 2012 12:16 PM
To: [email protected]; Discussions related to Mono for Android
Subject: Re: [mono-android] Bluetooth Service Discovery failed exception

On Sep 19, 2012, at 3:01 PM, "Steve Sharrock" <[email protected]> wrote:
> I'm trying to add support for a bluetooth device in one of our
applications based on the code from the latest Bluetooth Chat example on
GitHub. On every attempt to perform socket.Connect() I get the
Java.IO.IOException "Service discovery failed".

I see you found the advice to call CancelDiscovery():

        http://stackoverflow.com/a/8752294/83444

Now you probably need to try the "hack" solution:

        http://stackoverflow.com/a/3397739/83444
> Method m = device.getClass().getMethod("createRfcommSocket", new 
> Class[] {int.class}); socket = (BluetoothSocket) m.invoke(device, 1);


Unfortunately that solution relies on Java reflection, which we don't
currently expose. It thus needs to be translated to JNI:

        IntPtr createRfcommSocket = JNIEnv.GetMethodID(device.Class.Handle,
"createRfcommSocket", "(I)Landroid/bluetooth/BluetoothSocket;");
        IntPtr _socket = JNIEnv.CallObjectMethod(device.Handle,
createRfcommSocket, new Android.Runtime.JValue(1));
        socket = Java.Lang.Object.GetObject<BluetoothSocket>(_socket,
JniHandleOwnership.TransferLocalRef);

 - Jon


_______________________________________________
Monodroid mailing list
[email protected]

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

Reply via email to