有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Android上发现蓝牙设备(示例)不起作用

   final BroadcastReceiver bReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                 BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                 BTArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                 BTArrayAdapter.notifyDataSetChanged();
            }
        }
    };

   public void find(View view) {
       if (myBluetoothAdapter.isDiscovering()) {
           myBluetoothAdapter.cancelDiscovery();
       }
       else {
            BTArrayAdapter.clear();
            myBluetoothAdapter.startDiscovery();

            registerReceiver(bReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));    
        }    
   }

按“findBtn”时,没有任何设备。开发者的简单代码。安卓通用域名格式。如何正确发现?代码中有错误吗? 例如here


共 (1) 个答案