[mono-android] Bluetooth Connect NullPointerException
Jonathan Pryor
jonp at xamarin.com
Tue Oct 16 13:53:42 UTC 2012
On Oct 16, 2012, at 9:38 AM, Steve Sharrock <steve at sharkcode.com> wrote:
> 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 ) );
Is socketHandle IntPtr.Zero?
> 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?
What's the full stack trace that you get?
Java.Lang.Object.GetObject<T>() should return null if the handle is IntPtr.Zero.
- Jon
More information about the Monodroid
mailing list