Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何检测可恢复RSSI值?_Android_Listview_Bluetooth Lowenergy - Fatal编程技术网

Android 如何检测可恢复RSSI值?

Android 如何检测可恢复RSSI值?,android,listview,bluetooth-lowenergy,Android,Listview,Bluetooth Lowenergy,我正在尝试开发一款能够检测BLE信号并显示其RSSI值(除其他参数外)的应用程序。从现在起,我能够检测BLE并将其列在列表视图中,但当检测到参数RSSI时,我一直在研究如何将其传递给我为列表视图开发的BaseAdapter 这是我用来检测BLE设备的代码: // Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallbac

我正在尝试开发一款能够检测BLE信号并显示其RSSI值(除其他参数外)的应用程序。从现在起,我能够检测BLE并将其列在
列表视图中
,但当检测到参数RSSI时,我一直在研究如何将其传递给我为
列表视图
开发的
BaseAdapter

这是我用来检测BLE设备的代码:

// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
    new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
            addDevice(device);
        }
    };
这里是在另一个类中实现的addDevice代码,它是上面的代码:

protected synchronized void addDevice(final BluetoothDevice device) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mLeDeviceListAdapter.addDevice(device);
            mLeDeviceListAdapter.notifyDataSetChanged();
        }
    });
}
最后,这里是我用于
列表视图的
BaseAdapter

public class LeDeviceListAdapter extends BaseAdapter {
private List<BluetoothDevice> data;
private Activity context;



public LeDeviceListAdapter(Activity context, List<BluetoothDevice> data) {
    this.data = data;
    this.context = context;
}

public synchronized void addDevice(BluetoothDevice device) {
    if(!data.contains(device) ){
    data.add(device);
    }
}

@Override
public int getCount() {
    return data.size();
}

@Override
public Object getItem(int position) {
    return data.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (null == convertView) {
        LayoutInflater mInflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.leaf_devices_list_item, null);
        convertView.setTag(new DeviceView(convertView));
    }
    DeviceView view = (DeviceView) convertView.getTag();
    view.init((BluetoothDevice) getItem(position), null);
    return convertView;
}

public class DeviceView {


    private TextView title;
    private TextView status;
    private TextView type;
    private TextView address;
    private TextView rssivalue;

    public DeviceView(View view) {
        title = (TextView) view.findViewById(R.id.device_name);
        status = (TextView) view.findViewById(R.id.device_status_txt);
        type = (TextView) view.findViewById(R.id.device_type_txt);
        address = (TextView) view.findViewById(R.id.device_address_txt);
        rssivalue = (TextView) view.findViewById(id.signal_intensity_txt);
    }

    public void init(BluetoothDevice device, Intent intent) {
        title.setText(device.getName());
        address.setText(device.getAddress());
        setType(device.getType());
        setStatus(device.getBondState());
    }
}
public类LeDeviceListAdapter扩展BaseAdapter{
私人名单数据;
私人活动语境;
public-LeDeviceListAdapter(活动上下文、列表数据){
这个数据=数据;
this.context=上下文;
}
公共同步void addDevice(蓝牙设备){
如果(!data.contains(设备)){
数据添加(设备);
}
}
@凌驾
public int getCount(){
返回data.size();
}
@凌驾
公共对象getItem(int位置){
返回数据。获取(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
if(null==convertView){
拉平机=
(LayoutFlater)context.getSystemService(context.LAYOUT\u充气机\u服务);
convertView=mInflater.充气(R.layout.leaf\u设备\u列表\u项,空);
setTag(新设备视图(convertView));
}
DeviceView视图=(DeviceView)convertView.getTag();
view.init((BluetoothDevice)getItem(位置),null);
返回视图;
}
公共类设备视图{
私有文本视图标题;
私有文本视图状态;
私有文本视图类型;
私有文本视图地址;
私有文本视图rssivalue;
公共设备视图(视图){
title=(TextView)view.findViewById(R.id.device\u name);
status=(TextView)view.findViewById(R.id.device\u status\u txt);
type=(TextView)view.findViewById(R.id.device\u type\u txt);
地址=(TextView)view.findViewById(R.id.device\u address\u txt);
rssivalue=(TextView)view.findViewById(id.signal\u intensity\u txt);
}
public void init(蓝牙设备,意图){
title.setText(device.getName());
address.setText(device.getAddress());
setType(device.getType());
setStatus(device.getBondState());
}
}
“rssivalue”是我将用来显示RSSI的
TextView


我已经从我认为与此相关的每个类中获取了部分代码。如果需要,我将提供对本案例非常重要的代码。请有人帮助我解决此问题!!!

LeScanCallback
添加rssi值:

private BluetoothAdapter.LeScanCallback mLeScanCallback =
    new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
             yourBleAdapter.addDevice(device, rssi);
        }
    };  
在适配器中,这将成为:

public void addDevice(BluetoothDevice device, int rssi) {
       //get device and its rssi locally here
    }

这就是从中获取rssi值的地方。它来自我使用的示例代码。有效。

我尝试过,但我不知道如何在适配器中实现它,以便显示它。我应该修改代码的哪一部分以获取have?在addDevice中,我必须将参数更改为:(BluetoothDevice,int rssi)?删除了上面的一条评论,该评论包含github项目链接-现在是404