旨在学习记录把搜索到的设备添加显示的整个java层的流程,细节的东西暂无深入。
在蓝牙设置界面:
进入界面以后类BluetoothSettings用于显示蓝牙的列表信息,此类继承DeviceListPreferenceFragment.这个父类很关
键,它实现BluetoothCallback接口,这个接口是Settingslib模块里面的. 而在Settings模块的mk文件中有把此模块编译引
入。下面先简单看一下Settingslib中的这个BluetoothCallback接口.
package com.android.settingslib.bluetooth;/*** BluetoothCallback provides a callback interface for the settings* UI to receive events from {@link BluetoothEventManager}.*/public interface BluetoothCallback {void onBluetoothStateChanged(int bluetoothState);void onScanningStateChanged(boolean started);void onDeviceAdded(CachedBluetoothDevice cachedDevice);void onDeviceDeleted(CachedBluetoothDevice cachedDevice);void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState);void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state);}
从各个函数的名字也可以看出每个函数的大概功能。而我们目前关注的是每个搜索到的蓝牙设备是如何添加到列表进行显示的,那么
我们关注
onDeviceAdded.
可以由前面可知
DeviceListPreferenceFragment
实现了settingslib包中的BluetoothCallBack.在
DeviceListPreference
Fragment
当中我们看
onDeviceAdded
具体实现如下:
public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
if (mDevicePreferenceMap.get(cachedDevice) != null) {
return;
}
// Prevent updates while the list shows one of the state messages
if (mLocalAdapter.getBluetoothState() != BluetoothAdapter.STATE_ON) return;
if (mFilter.matches(cachedDevice.getDevice())) {
createDevicePreference(cachedDevice);

最低0.47元/天 解锁文章
2050

被折叠的 条评论
为什么被折叠?



