We hooked up a BT protocol analyzer to monitor why connection getting
dropped right after connection. We are certain it is due to "Role Switch".
By disable role switch, I have successfully established connection, read
and write.
The behavior seems not right, and I think there may be a problem on my
Android phones. The following is what I observed from the protocol
analyzer:
1. Android makes a connection to remote device. It is succesful.
2. Remote device requests "Role Switch".
=> Android "must" response yes (I believe, otherwise, connection
would just stay and no further steps shall take place)
3. Android immediately disconnects the above connection.
4. The remote device attempts to establish a connection to my Android
phone, it fails. I can see the remote device trying to negotiate connection
rate but eventually giving up.
The above I believe 3 and 4 are the steps when role switch taken place. I
could be wrong but by disable role switch on remote device, the connection
is fairly robust.
May I request "role switch" feature for next release?
Best regards,
Sean
On Tue, Nov 24, 2009 at 12:45 PM, Sean Liao <[email protected]> wrote:
> Hi, I wrote a simple test driver to test the bluetooth apis. Anyone can
> verify whether I am using the API correctly? Everything seems good but no
> data read :-(
>
>
>
> ===========================================================================
> // before calling the following, inquiry scan successfully returned, and
> the remote device is pre-paired.
>
> private boolean doTestConnection() {
>
> Log.d("SwxBtCommImpl", "doTestConnection");
>
> String btAddr = "00:08:1B:CA:C7:29";
>
> BluetoothDevice btdev =
> BluetoothAdapterImpl.getInstance().getRemoteDevice(btAddr);
>
> // widcom using the following GUID
> // 00001101-0000-1000-8000-00805F9B34FB
> UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
>
> try {
> BluetoothSocket btsocket =
> btdev.createRfcommSocketToServiceRecord(uuid);
>
> btsocket.connect();
> Log.d("SwxBtCommImpl", "connected");
>
> try {
> Thread.sleep(1000);
> } catch (InterruptedException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
>
> InputStream instream = btsocket.getInputStream();
> Log.d("", "getInputStream");
>
> byte[] data = new byte[512];
> for (int i = 0; i < 20; i++) {
> int numOfAvailable = instream.available();
>
> Log.d("SwxBtCommImpl", "read " + i + ": " + numOfAvailable + "
> bytes");
> if(numOfAvailable > 0) {
> int numOfRead = instream.read(data);
> Log.d("SwxBtCommImpl", new String(data) + "-" + numOfRead);
> } else {
>
> try {
> Thread.sleep(500);
> } catch (InterruptedException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> }
>
> instream.close();
> instream = null;
>
> btsocket.close();
>
> } catch (IOException e) {
> // TODO Auto-generated catch block
> Log.e("", "bt connection failed", e);
> }
>
>
>
> return true;
> }
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en