在Android上发现蓝牙设备(示例)无法正常工作

时间:2017-03-19 18:58:05

标签: java android bluetooth

   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”时,没有任何设备。 developer.android.com上的简单代码。如何正确发现?代码中的任何错误? 示例here

1 个答案:

答案 0 :(得分:0)