[mono-android] Bluetooth Connect NullPointerException
Steve Sharrock
steve at sharkcode.com
Tue Oct 16 13:38:39 UTC 2012
I'm aware of the reflection required to get the Socket...
IntPtr createRfcommSocket = JNIEnv.GetMethodID( device.Class.Handle,
"createRfcommSocket", "(I)Landroid/bluetooth/BluetoothSocket;" );
IntPtr socketHandle = JNIEnv.CallObjectMethod( device.Handle,
createRfcommSocket, new JValue( 1 ) );
s = Java.Lang.Object.GetObject<BluetoothSocket>( socketHandle,
JniHandleOwnership.TransferLocalRef );
I've been testing with different Barcode Scanners and RFID Readers and most
of them work fine, except one scanner paired with a Galaxy Tab 2. A Google
search revealed that the Galaxy Tab 2 does have some Bluetooth issues, and
the recommended work-around is to use an Insecure Socket.
IntPtr createInsecureRfcommSocket = JNIEnv.GetMethodID( device.Class.Handle,
"createInsecureRfcommSocket", "(I)Landroid/bluetooth/BluetoothSocket;" );
IntPtr socketHandle = JNIEnv.CallObjectMethod( device.Handle,
createInsecureRfcommSocket, new JValue( 1 ) );
s = Java.Lang.Object.GetObject<BluetoothSocket>( socketHandle,
JniHandleOwnership.TransferLocalRef );
This doesn't work for me either and throws the NullPointerException when I
try Socket.Connect(). Is my syntax correct in the Insecure code snippet?
Any help is appreciated, thanks.
Steve Sharrock
Architecture/Design/Programming
www.sharkcode.com <blocked::http://www.sharkcode.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20121016/964d6207/attachment.html>
More information about the Monodroid
mailing list