[mono-android] Bluetooth rfcomm

Goncalo Oliveira goncalo at minkan.net
Tue Feb 7 15:34:26 UTC 2012


Thank you for the feedback Bartosz. I tried reading directly but I keep on
getting this exception

+ ex {Java.IO.IOException: Exception of type 'Java.IO.IOException' was
thrown.
  at Android.Runtime.JNIEnv.CallIntMethod (IntPtr jobject, IntPtr jmethod,
Android.Runtime.JValue[] parms) [0x00024] in
/home/jpobst/Desktop/monodroid/Mono.Android/src/Runtime/JNIEnv.g.cs:264
  at Java.IO.InputStream.Read (System.Byte[] b, Int32 offset, Int32 length)
[0x00045] in
/home/jpobst/Desktop/monodroid/Mono.Android/platforms/android-10/src/generated/Java.IO.InputStream.cs:244
  at Android.Runtime.InputStreamInvoker.Read (System.Byte[] buffer, Int32
offset, Int32 count) [0x00000] in
/home/jpobst/Desktop/monodroid/Mono.Android/src/Runtime/InputStreamInvoker.cs:22
  at
MonoAndroidApplication1.Services.BluetoothCommService.ReadingThreadWorker
(System.Object objSocket) [0x0001e] in
C:\Projects\Tests\MonoAndroidApplication1\Services\BluetoothCommService.cs:81
  --- End of managed exception stack trace ---
*java.io.IOException: Software caused connection abort*
at android.bluetooth.BluetoothSocket.readNative(Native Method)
at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:404)
at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
at dalvik.system.NativeStart.run(Native Method)
} Java.IO.IOException

Can't figure out what I'm doing wrong. I read the chat sample, and it
doesn't look like I'm doing things differently.


On 7 February 2012 15:18, Bartosz Skalski <bartosz.skalski at gmail.com> wrote:

> I read directly from the InputStream without the StreamReader and it
> works, try:
>
> socket.InputStream.Read( buffer, 0, buffer.Length )
>
> Cheers
>
>
> 2012/2/7 Jonathan Pobst <monkey at jpobst.com>
>
>> Not sure if it helps, but we have a sample that uses bluetooth:
>>
>> https://github.com/xamarin/**monodroid-samples/tree/master/**
>> BluetoothChat<https://github.com/xamarin/monodroid-samples/tree/master/BluetoothChat>
>>
>> Jonathan
>>
>>
>>
>> On 2/7/2012 8:40 AM, ledz wrote:
>>
>>> I'm having some trouble on using bluetooth with rfcomm on a custom
>>> device. I
>>> am able to connect the socket, it seems, but I can't retrieve anything
>>> from
>>> the output stream; just keep on getting an io exception and the
>>> connection
>>> drops. Can someone give me a few pointers if I'm doing anything wrong,
>>> or if
>>> there are any exceptions where this won't work?
>>>
>>> I'm basically connecting through a RfcommSocketToService
>>>
>>> private UUID ServiceUUID = UUID.FromString(
>>> "00001101-0000-1000-8000-**00805F9B34FB" );
>>> ...
>>> socket = device.**CreateRfcommSocketToServiceRec**ord( ServiceUUID );
>>> ...
>>> StreamReader reader = new StreamReader( socket.InputStream );
>>> ...
>>> int n = reader.ReadBlock( buffer, 0, buffer.Length );
>>>
>>>
>>> I'm running this over an Android 2.3.6 smartphone (Samsung GT-N7000).
>>> I posted a sample of my code here: http://pastebin.com/j9MmdDwQ
>>>
>>> Cheers
>>>
>>>
>>> --
>>> View this message in context: http://mono-for-android.**
>>> 1047100.n5.nabble.com/**Bluetooth-rfcomm-**tp5463305p5463305.html<http://mono-for-android.1047100.n5.nabble.com/Bluetooth-rfcomm-tp5463305p5463305.html>
>>> Sent from the Mono for Android mailing list archive at Nabble.com.
>>> ______________________________**_________________
>>> Monodroid mailing list
>>> Monodroid at lists.ximian.com
>>>
>>> UNSUBSCRIBE INFORMATION:
>>> http://lists.ximian.com/**mailman/listinfo/monodroid<http://lists.ximian.com/mailman/listinfo/monodroid>
>>>
>>>
>>>
>> ______________________________**_________________
>> Monodroid mailing list
>> Monodroid at lists.ximian.com
>>
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/**mailman/listinfo/monodroid<http://lists.ximian.com/mailman/listinfo/monodroid>
>>
>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>


-- 
Gonçalo Oliveira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20120207/e04f5b2a/attachment-0001.html>


More information about the Monodroid mailing list