Skip to content Skip to sidebar Skip to footer

Bluetoothserversocket Accept Fails And Throws An Ioexception

I have a device which supports the OBEX Object Push Profile, this profile is based upon the Serial Port Profile. My guess is that I can use the Android Bluetooth Chat example for c

Solution 1:

I finally solved it, the problem is that different Android Versions and different devices seemes to need different sockets. I tryed it with Samsung Galaxy XCOVER, Tab1, Tab2, Nexus, Note, Motorola Defy and HTC Flyer. The Sockets I used are:

A:

Method m = mmDevice.getClass().getMethod("createRfcommSocket", newClass[] { int.class });
mSocket = (BluetoothSocket) m.invoke(mmDevice, Integer.valueOf(1));

B:

Method m = mmDevice.getClass().getMethod("createInsecureRfcommSocket", newClass[]{int.class});
mSocket=(BluetoothSocket)m.invoke(mmDevice,Integer.valueOf(1));

C:

mSocket=BluetoothAdapter.getDefaultAdapter().getRemoteDevice(mmDevice.getAddress()).createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));

Android 4.0.x works for Nexus, Flyer,Tab1 with A,B Android 4.0.3 works for Tab2 with B Android 3,6,x works for DEFY with A,B Android 2.3.6 works for XCOVER with C

I can't find a solution witch works for all devices and I;m not able to find out witch socket will work before I create and use the Socket, especially the XCOVER perform the connect() for all Sockets without throwing an exception, but catch if i try tro write(). So if you want to setup a bloothoh connection wich works for all devices you have to create the sockets, connect an write and then remeber the socket wich works (e.g. in preferences)

Post a Comment for "Bluetoothserversocket Accept Fails And Throws An Ioexception"