如何断开A2DP配置文件蓝牙连接?

问题描述 投票:1回答:1

我正在与耳机和其他蓝牙设备进行A2DP连接,但是当我连接蓝牙设备但我断开但它没有与它断开连接时。我的代码是:

try {    
    Method connect = mA2dpService.getClass().getDeclaredMethod("disconnect", BluetoothDevice.class);
    connect.invoke(device);
} catch (Exception e) {
     e.printStackTrace();
}
android bluetooth a2dp
1个回答
1
投票

终于我找到了

调用getProfileProxy以获取a2dp代理

adapter.getProfileProxy(c, listner, BluetoothProfile.A2DP);

监听器应该在A2DPProxy Received上实现。

然后将调用回调onA2DPProxyReceived。

public void onA2DPProxyReceived (BluetoothA2dp proxy) {
    Method disconnect = null;
    try {
        disconnect = BluetoothA2dp.class.getDeclaredMethod("disconnect", BluetoothDevice.class);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    BluetoothDevice device = findBondedDeviceByName(mBtAdapter, myDevice);
    disconnect.setAccessible(true);
    try {
        int result = disconnect.invoke(proxy,device);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

请参阅以下网站

© www.soinside.com 2019 - 2024. All rights reserved.