车机的蓝牙共享网络,优先级是高于wifi的,所以,如果打开了蓝牙共享网络,会导致,wifi连接不上的问题,因此,有些项目中,特别是使用无线手机互联的项目中,会需求禁用蓝牙共享网络
对于AC8257,禁用的方式是这样的
- 监听BluetoothPan的广播
intentFilter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
- 接收到广播以后,再执行下面代码
int connectState = intent.getIntExtra(BluetoothHeadsetClient.EXTRA_STATE, BluetoothHeadsetClient.STATE_DISCONNECTED);
BluetoothDevice bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (bluetoothDevice != null && connectState == BluetoothProfile.STATE_CONNECTED) {
bluetoothAdapter.getProfileProxy(context, new BluetoothProfile.ServiceListener() {
@Override
public void onServiceConnected(int i, BluetoothProfile bluetoothProfile) {
Log.i(TAG, "BTServiceOnReceive BluetoothPan.ACTION_CONNECTION_STATE_CHANGED connected");
if (i == BluetoothProfile.PAN) {
BluetoothPan bluetoothPan = (BluetoothPan) bluetoothProfile;
bluetoothPan.disconnect(bluetoothDevice);
}
}
@Override
public void onServiceDisconnected(int i) {
Log.i(TAG, "BTServiceOnReceive BluetoothPan.ACTION_CONNECTION_STATE_CHANGED disconnected");
}
}, BluetoothProfile.PAN);
}
bluetoothAdapter.getProfileProxy
是获取蓝牙的某个协议的Profile;但在获取BluetoothPan这个Profile的时候,没有连接的时候,总是获取失败;它应该是有一时机可以获取,目前试到的是监听BluetoothPan这个广播再去获取;这样是可行的,是否有其它时机,还可以再去尝试