Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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 9-BluetoothAdapter startDiscovery()未找到以前找到的设备_Android_Bluetooth - Fatal编程技术网

Android 9-BluetoothAdapter startDiscovery()未找到以前找到的设备

Android 9-BluetoothAdapter startDiscovery()未找到以前找到的设备,android,bluetooth,Android,Bluetooth,我有一个安卓应用程序已经有好几年的历史了,并且一直工作到安卓9。我的应用程序将扫描本地蓝牙设备并在应用程序上显示它们。它可以通过在默认的BluetoothAdapter上执行startDiscovery()来实现这一点,并通过为BluetoothDevice.ACTION\u found注册一个BroadcastReceiver来捕获所有找到的设备 Android 9之前的版本,这很好用。我不确定Android的确切版本是否停止工作,也许Android 8也坏了 在Android 9之后,它只工

我有一个安卓应用程序已经有好几年的历史了,并且一直工作到安卓9。我的应用程序将扫描本地蓝牙设备并在应用程序上显示它们。它可以通过在默认的BluetoothAdapter上执行startDiscovery()来实现这一点,并通过为BluetoothDevice.ACTION\u found注册一个BroadcastReceiver来捕获所有找到的设备

Android 9之前的版本,这很好用。我不确定Android的确切版本是否停止工作,也许Android 8也坏了

在Android 9之后,它只工作一次。这意味着在我的第一次startDiscovery()中,我将为所有设备找到Bluetooth.ACTION\u,但如果我退出应用程序并执行第二次startDiscovery(),则不会再次找到设备。就像安卓9正在缓存结果,却没有给我清除缓存或从缓存中获取结果的方法。如果我禁用然后重新启用蓝牙设备,它将获得新的扫描结果

下面是注册BroadcastReceiver的代码(这基本上是Google提供的演示代码):

startScan()和BluetoothLeScanner.startScan()工作正常,但我无法使用这些函数,因为此应用程序还支持不可复制的设备


我一定错过了一些简单的东西。

我在使用BLE时遇到了同样的问题,我必须重新启动设备才能工作。同样的问题。你找到解决办法了吗?还没有,请把问题投上去,让更多的人看到。由于该应用程序主要支持BLE设备,我只需使用BLE方法重新扫描即可,但遗憾的是,仍然找不到经典的BL设备。
@Override
protected void onCreate(Bundle savedInstanceState) {
    ...

    // Register for broadcasts when a device is discovered.
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, filter);
}

// Create a BroadcastReceiver for ACTION_FOUND.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Discovery has found a device. Get the BluetoothDevice
            // object and its info from the Intent.
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            String deviceName = device.getName();
            String deviceHardwareAddress = device.getAddress(); // MAC address
        }
    }
};

@Override
protected void onDestroy() {
    super.onDestroy();
    ...

    // Don't forget to unregister the ACTION_FOUND receiver.
    unregisterReceiver(mReceiver);
}