This is a hidden API. It might work, it might not, it almost definitely will break at some point.
On Fri, Feb 5, 2010 at 2:10 PM, Sean Liao <[email protected]> wrote: > how come I cannot see the method: > Method m = btdev.getClass().getMethod("createRfcommSocket", new Class[] { > int.class }); > > Anything wrong with my dev/sdk env? or is it a hidden API? > On Thu, Feb 4, 2010 at 2:33 AM, Bwd <[email protected]> wrote: >> >> Good day. >> I was able to create a stable connection to the BT device. >> To do this, I changed your code: >> BluetoothSocket btsocket = >> btdev.createRfcommSocketToServiceRecord(uuid); >> btsocket.connect(); >> >> Upon: >> int RFCOMM_CHANEL = 1; //SPP chanel >> Method m = btdev.getClass().getMethod("createRfcommSocket", new >> Class[] { int.class }); >> BluetoothSocket connection = (BluetoothSocket) m.invoke(btdev, >> RFCOMM_CHANEL); >> connection.connect(); >> >> And now the connection has been stable and not broken and you can read >> and receive data by input and output streams. >> >> >> On 16 янв, 02:48, Sean Liao <[email protected]> wrote: >> > Anyone look into or experienced the same problem using the role switch >> > feature? I think this may be a bug on the android sdk: >> > >> > If android bt advertise it support role switch and it should fullfil the >> > request from remote device. Or, it should simply advertise that it >> > doesn't >> > support role switch so the remote device would not request role switch? >> > >> > is that how it suppose to work? comments? >> > >> > On Mon, Nov 30, 2009 at 11:36 AM, Sean Liao <[email protected]> >> > wrote: >> > > 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 > > -- > 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 -- 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

