Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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 使用FetchUUIDSWithDP()防止友好名称缓存_Android_Bluetooth_Android Bluetooth - Fatal编程技术网

Android 使用FetchUUIDSWithDP()防止友好名称缓存

Android 使用FetchUUIDSWithDP()防止友好名称缓存,android,bluetooth,android-bluetooth,Android,Bluetooth,Android Bluetooth,定义: 我的非android设备NAD是一款蓝牙设备,它将名称从60循环到0,并以无限方式重置 目标: 我想做的是让我的android设备尽可能近距离地检测倒计时,并启动一个尽可能接近NAD计数器的警报 为此,我将设备的本机BluetoothAdapter手动启动查看,将此功能绑定到屏幕上的按钮,并通过广播接收器关注我设置的祝酒词,广播接收器更新屏幕上的文本视图,使我能够实时监控设备接收到的内容 要求: 在这种情况下,系统和资源效率不是一个问题 问题:请注意代码中的第1部分和第2部分 我不确定使

定义:

我的非android设备NAD是一款蓝牙设备,它将名称从60循环到0,并以无限方式重置

目标: 我想做的是让我的android设备尽可能近距离地检测倒计时,并启动一个尽可能接近NAD计数器的警报

为此,我将设备的本机BluetoothAdapter手动启动查看,将此功能绑定到屏幕上的按钮,并通过广播接收器关注我设置的祝酒词,广播接收器更新屏幕上的文本视图,使我能够实时监控设备接收到的内容

要求: 在这种情况下,系统和资源效率不是一个问题

问题:请注意代码中的第1部分和第2部分 我不确定使用FetchUUIDSWITHDP对我有何帮助,因为它更新的TextView仍然为空,并且TextView由额外的\u名称填充,额外的意图返回操作\u名称\u更改的是缓存的初始发现名称,即,我的应用程序在初始发现后没有读取名称

我的代码可以在下面找到

对于新手犯的错误,我深表歉意,我正在尽最大努力:


我曾参与过一个蓝牙项目,我认为发现过程应该是一个可以在后台注册的意图。要发现范围内的设备,只需调用BTDevice.startDiscovery来搜索它们。 通常,如果连续启用,startDiscovery会耗尽蓄电池电量。 如果你愿意,我可以编辑这篇文章来分享我用来扫描设备的狙击手。 希望这有帮助

    public class BTBroadcastReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            //pulling the action name from the broadcasted intent
            String action = intent.getAction();
            if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
                sToaster("StartedD");//show toast that Discovery has started

            }
            else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
                sToaster("EndedD");//show toast signifying end of discovery
                /*
                if(notfound){
                    mBTAdapter.startDiscovery();
                }*/
            }
            else if(BluetoothDevice.ACTION_FOUND.equals(action)){
                //when a device is found
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                //make sure it's indeed my NAD device by checking MAC address
                if(device.getAddress().equals(MACAddress)){
                    if(notfound){
                        //show device name on screen
                        sToaster("FOUND DEvice");
                        notfound = false;
                        NAD = device;
                        NameShower.setText(device.getName());
                    }
                    else{
                        //do nothing if it's the second time the device is found
                    }
                }
            }
            else if(BluetoothDevice.ACTION_NAME_CHANGED.equals(action)){
                //name changed
                BluetoothDevice foundDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                //make sure it's indeed my NAD device
                if(foundDevice.equals(NAD)){
                    sToaster("Name Change!"); //show on screen that the name change intent has been caught

                    //PART1
                    //to prevent caching of the old device name StackOverflow article 
                    //advised using this function i don't totally understand yet
                    //NAD.fetchUuidsWithSdp();
                    //either commented or not commented the outcome is the same (no refresh of the name)



                    //PART2
                    //tried showing the new name two different ways below, neither of which are effective
                    //by inspecting the TextViews on-screen
                    NameShower.setText(foundDevice.getName());
                    EventView.setText(intent.getStringExtra(BluetoothDevice.EXTRA_NAME));
                    }
                }
            }

    };