如何解决如何使用listadapter在数据处于特定范围内时获得警报
我很抱歉,但我真的是编码初学者,但任何人都可以帮助我,我目前正在开发使用蓝牙 RSSI 计算距离的应用程序。我已经让应用程序在扫描设备时显示距离。但我的问题是我不知道如何让我的应用程序在距离低于特定范围时发出警报或警告。在我的情况下,我想让它在距离低于 2 米时发出通知或声音提醒。下面是我计算距离的代码,我使用 listview 来显示结果。
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context,Intent intent) {
double dist;
String action = intent.getAction();
IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(receiver,intentFilter);
//if conditions for printing the distance.
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
double rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
dist= Math.pow(10,(-69-(rssi))/(20));
DecimalFormat df2 = new DecimalFormat("#.##");
String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
ListAdapter.add(name + " => " + rssi + "dBm\nDistance => " + df2.format(dist) +" metres\n" );
ListAdapter.notifyDataSetChanged();
}
this is how my apps currently is
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。