2

我正在尝试修改蓝牙聊天程序以通过 A2DP 配置文件与设备连接。我的平板电脑已经配对并连接到设备,但是当我启动程序时它说它无法连接。这是我更改的唯一代码:

public BluetoothChatService(Context context, Handler handler) {
    mAdapter = BluetoothAdapter.getDefaultAdapter();
    mState = STATE_NONE;
    mHandler = handler;

    mAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.A2DP);
}
    private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (profile == BluetoothProfile.A2DP) {
                mBluetoothA2DP = (BluetoothA2dp) proxy;
            }
        }
        public void onServiceDisconnected(int profile) {
            if (profile == BluetoothProfile.A2DP) {
                mBluetoothA2DP = null;
            }
        }

    };

这在 BluetoothChatService.java 文件中。在此代码上方,我定义了私有 BluetoothA2dp mBluetoothA2DP;

4

0 回答 0