0

我是安卓新手。我正在尝试扫描其他蓝牙设备。请指导我并帮助我找到解决方案。这是代码的一部分:

scan_btn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        mBluetoothAdapter.startDiscovery();
        mReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
                if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                    BluetoothDevice device = Untent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                }
            }
        };
        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
        registerReceiver(mReceiver, filter); 
    }
});

@Override
protected void onDestroy() {
    super.onDestroy();
    unregisterReceiver(mReceiver);//unregister the receiver
}

在此处输入图像描述

4

1 回答 1

1

您的按钮是切换按钮。确保您的代码是 -

 mToggleButton = (ToggleButton) findViewById(R.id.toggleButton);
 mToggleButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    }
于 2012-04-23T12:04:45.700 回答