Android 5.0.1 Nexus 9未在蓝牙列表中显示已连接的设备

时间:2015-02-22 21:42:20

标签: android bluetooth android-5.0-lollipop a2dp

我的蓝牙耳机设备连接到运行Android 5.0.1的Nexus 9。

我的应用程序运行以下代码,我调用getA2dpConnectedDevice()来检查A2DP状态。我希望,因为应用程序设备应该连接到BluetoothProfile.ServiceListener()。onServiceConnected会触发的耳机,但它不会。

private void getA2dpConnectedDevice() {
    // Establish connection to the proxy.
    mBluetoothAdapter.getProfileProxy(this, mA2dpProfileListener,
            BluetoothProfile.A2DP);
    logAndPostMessage( "Requesting A2DP connection status");
}

private BluetoothProfile.ServiceListener mA2dpProfileListener = new BluetoothProfile.ServiceListener() {
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.A2DP) {
            mBluetoothA2dp = (BluetoothA2dp) proxy;
            ArrayList<BluetoothDevice> a2DPdevices = (ArrayList) mBluetoothA2dp
                    .getDevicesMatchingConnectionStates(new int[] { BluetoothA2dp.STATE_CONNECTED });
            // if any connected devices, should only be one
            if (a2DPdevices.size() > 0) {
                addDeviceToDeviceMap(a2DPdevices.get(0), null);
                // post connected msg
                logAndPostMessage(  "A2DP is connected. Fired A2DPStatusUpdate event");
                post(new A2DPStatusUpdate(a2DPdevices.get(0),
                                BluetoothA2dp.STATE_CONNECTED));
                getHeadsetConnectedDevice();

            }
        }
    }

我认为上述代码应该有效吗?

奇怪的是(也许真的线索在Android中存在问题),虽然状态栏中的蓝牙图标表示耳机已连接,但当我进入蓝牙设置屏幕时,我看不到耳机一点都不

任何智慧的话都会受到赞赏。

0 个答案:

没有答案