1

I am developing an app for bluetooth remote control a small robot (no, not arduino). The robot has a bluetooth chip (BK3221), which, from what I've gotten to know through their UUIDs works with A2DP and AVRCP protocols (oriented audio).

UUID 1: 0000110b-00000-1000-8000-00805f9b34fb

UUID 2: 0000110e-00000-1000-8000-00805f9b34fb

I can create the connection of the mobile and device through the connect() of Bluetooth A2DP classbut that is what I have, I have the proxy and the connected device but I do not know how to give information .

Moreover I tried program the connection in a basic way with functions for android with RFCOMM (which is supposed to support AVRCP). The robot is a closed system and I don´t know if it worked as a server or client (I assumed it was because the server because it accepts the conexion with the function "conect()" in the previous case). But when I call the connect function generates an exception BluetoothSocket me: "JSR82 connect connection is not created (failed or aborted)". I looked on JSR82 but gave me the feeling of being obsolete ...

If anyone has any idea of ​​something... Thanks

Code of the connection with BluetoothA2dp:

 //adaptador == BluetoothAdapter and proxy1 == BluetoothA2dp

protected Boolean doInBackground(BluetoothDevice device) throws RemoteException {
  Method connect = getConnectMethod();
  final BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {             
  public void onServiceConnected(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.A2DP) {
               proxy1 = (BluetoothA2dp) proxy;
                }
        }
  public void onServiceDisconnected(int profile) {
        if (profile == BluetoothProfile.A2DP) {
               proxy1 = null;        }
  }};
   adaptador.getProfileProxy(getBaseContext(), mProfileListener, BluetoothProfile.A2DP);
    try {
      connect.setAccessible(true);
      connect.invoke(proxy1, device);
    Toast.makeText(getBaseContext(),"Connection OK!", Toast.LENGTH_LONG).show();
    } catch (Exception ex) {
        Toast.makeText(getBaseContext(),"Connection Error"+ex.getMessage(), Toast.LENGTH_LONG).show();
        }



 private Method getConnectMethod () {
                try {
                    return BluetoothA2dp.class.getDeclaredMethod("connect", BluetoothDevice.class);
                } catch (NoSuchMethodException ex) {
                    Toast.makeText(getBaseContext(),"Method dont appear", Toast.LENGTH_LONG).show();
                    return null;
                }
            }
4

0 回答 0