Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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
如何在java中刷新蓝牙设备列表_Java_Android Studio_Bluetooth_Localization - Fatal编程技术网

如何在java中刷新蓝牙设备列表

如何在java中刷新蓝牙设备列表,java,android-studio,bluetooth,localization,Java,Android Studio,Bluetooth,Localization,我正在尝试制作一个关于本地化的android应用程序,但是我正在尝试制作一个由我的智能手机找到的蓝牙设备列表,并每10秒刷新一次列表信息。我想这样做,因为我还记录了信号强度(RSSI),并想记录当信标移动时超出范围或信号变弱时。因此,刷新列表将有助于实现这一点。我在下面提供了我的一些代码 @覆盖受保护的void onResume(){ super.onResume(); registerReceiver(DeviceFoundReceiver,新的IntentFilter(BluetoothDe

我正在尝试制作一个关于本地化的android应用程序,但是我正在尝试制作一个由我的智能手机找到的蓝牙设备列表,并每10秒刷新一次列表信息。我想这样做,因为我还记录了信号强度(RSSI),并想记录当信标移动时超出范围或信号变弱时。因此,刷新列表将有助于实现这一点。我在下面提供了我的一些代码

@覆盖受保护的void onResume(){
super.onResume();
registerReceiver(DeviceFoundReceiver,新的IntentFilter(BluetoothDevice.ACTION_-FOUND));
registerReceiver(DeviceFoundReceiver,新的IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED));
registerReceiver(DeviceFoundReceiver,新的IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
}
private final BroadcastReceiver设备foundReceiver=new BroadcastReceiver(){
@凌驾
公共void onReceive(上下文、意图){
String action=intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(ACTION)){
BluetoothDevice=intent.getParcelableExtra(BluetoothDevice.EXTRA\u设备);
int rssid=intent.getShortExtra(BluetoothDevice.EXTRA\RSSI,Short.MIN\u值);
添加(device.getName()+“\n”+device.getAddress()+”\n“+”RSSI:“+rssid+”dBm”);
listAdapter.notifyDataSetChanged();
}else if(BluetoothAdapter.ACTION\u DISCOVERY\u FINISHED.equals(ACTION)){
scanningButton.setText(“扫描蓝牙设备”);
}else if(BluetoothAdapter.ACTION\u DISCOVERY\u STARTED.equals(ACTION)){
scanningButton.setText(“正在扫描…”);
}
}
};

使用列表视图,然后在适配器对象上调用
notifyDataSetChanged()

使用列表视图,然后在适配器对象上调用
notifyDataSetChanged()

我已经这样做了,但它不会刷新列表中的信息。在ListView中获取字符串对象并根据rssi变弱进行更改,否则连接将丢失。我已经这样做了,但它不会刷新列表中的信息。在ListView中获取字符串对象,并根据rssi变弱进行更改,否则连接将丢失。