我正在尝试修改蓝牙聊天程序,以通过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;