如何使用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 (将#修改为@)