Android6.0 蓝牙模块显示搜索到的设备的流程

 旨在学习记录把搜索到的设备添加显示的整个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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值