Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BluetoothManager bluetoothManager = (BluetoothManager)
- getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
- bluetoothAdapter = bluetoothManager.getAdapter();
- bluetoothAdapter.startDiscovery();
- IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
- getActivity().registerReceiver(mReceiver,filter);
- // Register for broadcasts when discovery has finished
- filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
- getActivity().registerReceiver(mReceiver,filter);
- public BroadcastReceiver mReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- Log.e("走进receiver","bluetooth");
- if (BluetoothDevice.ACTION_FOUND.equals(action)) {
- // Get the BluetoothDevice object from the Intent
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- // If it's already paired, skip it, because it's been listed already
- if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
- String sname = device.getName();
- } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement