closeProfileProxy не отключает мое Bluetooth-соединение A2DP, не знаю почему

#java #android #bluetooth #android-bluetooth #a2dp

Вопрос:

Я подключен к устройству Bluetooth с помощью профиля a2dp. Эта часть работает нормально, но когда приходит время отключаться, весь ожидаемый код доступен, но устройство не отключается, и я не уверен, что делаю неправильно. Это мой код отключения:

 public void disconnectFromOther(BluetoothDevice device) {  BluetoothProfile.ServiceListener serviceListener =  new BluetoothProfile.ServiceListener() {  @Override  public void onServiceDisconnected(int profile) {   }   public void onServiceConnected(int profile, BluetoothProfile proxy) {  Method disconnect;   try {  disconnect = a2dp.getClass()  .getMethod("disconnect", BluetoothDevice.class);  disconnect.setAccessible(true);  disconnect.invoke(proxy, device);  } catch (NoSuchMethodException e) {  e.printStackTrace();  } catch (IllegalAccessException e) {  e.printStackTrace();  } catch (InvocationTargetException e) {  e.printStackTrace();  }  BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy);  }  };  BluetoothAdapter.getDefaultAdapter().getProfileProxy(context, serviceListener, BluetoothProfile.A2DP); }  

Редактировать: Теперь я также попробовал Bluetooth, и я все еще не могу отключить свое устройство.

Ответ №1:

Оказывается, что второй профиль для гарнитуры (BluetoothProfile.ГАРНИТУРА) также открывалась, и я заметил это в выводе logcat. Закрытие этого профиля вместе с моим профилем a2dp закрыло соединение.