在android中发现可用的蓝牙设备

在android中发现可用的蓝牙设备,android,eclipse,bluetooth,Android,Eclipse,Bluetooth,我刚开始学习Android开发。我正在编写一个Android程序来扫描可用的蓝牙设备,并在日志文件中列出它们。由于我是Android新手,我无法找出下面代码片段中的错误 button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ListView lv1 = (ListView) fi

我刚开始学习Android开发。我正在编写一个Android程序来扫描可用的蓝牙设备,并在日志文件中列出它们。由于我是Android新手,我无法找出下面代码片段中的错误

 button2.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                ListView lv1 = (ListView) findViewById(R.id.myListView1);
                BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();


                final BroadcastReceiver mReceiver = new BroadcastReceiver() 
                { 
                    public void onReceive(Context context, Intent intent) 
                    {
                        String action = intent.getAction(); 
                        // When discovery finds a device 
                        if (BluetoothDevice.ACTION_FOUND.equals(action)) 
                        {
                        // Get the BluetoothDevice object from the Intent 
                        BluetoothDevice device = intent.getParcelableExtra(
                        BluetoothDevice.EXTRA_DEVICE);
                        Log.v("BlueTooth Testing",device.getName() + "\n"
                        + device.getAddress()); 
                        }
                    }    
                };

                String aDiscoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
                startActivityForResult(new Intent(aDiscoverable),DISCOVERY_REQUEST);
                IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
                registerReceiver(mReceiver, filter); 
                mBluetoothAdapter.startDiscovery();
            }
        });
当我尝试调试模式时,控件跳过广播接收器。我在日志中找不到任何条目。你能帮我找出问题所在,以及如何列出可用的蓝牙设备吗

[编辑] 我收到应用程序意外停止的错误消息:

Logcat Errors:
10-28 20:08:24.201: ERROR/UpdateReceiver(914): ACTION_PACKAGE_REMOVED
10-28 20:08:28.415: ERROR/RequestPermissionActivity(431): Timeout = 120
10-28 20:08:44.291: ERROR/DTUN_HCID4(521): === dtunops_stop_discovery() ===

您应该在清单中拥有BLUETOOTH和BLUETOOTH_管理权限

您应该在清单中拥有BLUETOOTH和BLUETOOTH_管理权限

不确定为什么要将此问题标记为basic4android。如果你真的想用Basic4android实现它,你应该看到这一点。很抱歉,我是android新手,我认为Basic4android是一个获取基本android编程相关答案的地方。我想用Java解决这个问题,但不知道为什么用basic4android标记这个问题。如果你真的想用Basic4android实现它,你应该看到这一点。很抱歉,我是android新手,我认为Basic4android是一个获取基本android编程相关答案的地方。我想用Java解决这个问题