蓝牙配对功能
配对手机,配对蓝牙耳机,配对电脑
(一)设置界面packages\Settings
A:搜索调用的地方:点击preference因为下面的条目是单独的一个所以到了blueetoothSettings的父类中。
目录:android\packages\apps\Settings\src\com\android\settings\bluetooth\DeviceListPreferenceFragment.java
void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
btPreference.onClicked();
}
B:
目录:android\packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothDevicePreference.java
void onClicked() {
int bondState = mCachedDevice.getBondState();
if (mCachedDevice.isConnected()) {
askDisconnect();------------------------断开连接
} else if (bondState == BluetoothDevice.BOND_BONDED) {
mCachedDevice.connect(true);已经配对了就连接
} else if (bondState == BluetoothDevice.BOND_NONE) {
pair();---------------------------没有配对就配对
}
}
private void pair() {
if (!mCachedDevice.startPairing()) {
Utils.showError(getContext(), mCachedDevice.getName(),
R.string.bluetooth_pairing_error_message);
}
}
C:配对mCachedDevice.startPairing())
目录:android\packages\apps\Settings\src\com\android\settings\bluetooth\CachedBluetoothDevice.java
boolean startPairing() {
if(mLocalAdapter.checkPairingState() == true)
{
return true;------------------------------正在配对就终止该方法
}
mLocalAdapter.setPairingState(true);
if (mLocalAdapter.isDiscovering()) {
mLocalAdapter.cancelDiscovery();------------------当前设备正在搜索,就取消搜索
}
if (!mDevice.createBond()) {
mLocalAdapter.setPairingState(false);
return false;
}
mConnectAfterPairing = true; // auto-connect after pairing
return true;
}
(二)走到frameworks
D:配对mDevice.createBond()
目录:android\frameworks\base\core\java\android\bluetooth\bluetoothDevice.java
public boolean createBond() {..............
return sService.createBond(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
private staticIBluetooth sService;
(三)走到frameworks的aidl文件
E:aidl文件
目录:android\frameworks\base\core\java\android\bluetooth\IBluetooth.aidl
boolean