kgandroid
kgandroid

Reputation: 5595

Strange behaviour with bluetooth discovery

I am implementing an app with bluetooth.Here I am facing a strange problem.I want to show all the devices available when I scan my bluetooth.But my app is only discovering the bluetooth`s of pc.The bluetooth of mobile phones or tabs are not showing.To implement bluetooth functionality I have used this tutorial.Here is the code to find bluetooth devices:

  final BroadcastReceiver bReceiver = 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);
                 // add the name and the MAC address of the object to the arrayAdapter
                 BTArrayAdapter.add(device.getName() + "\n" + device.getAddress());
                 BTArrayAdapter.notifyDataSetChanged();
            }
        }
    };

   public void find(View view) {
       if (myBluetoothAdapter.isDiscovering()) {
           // the button is pressed when it discovers, so cancel the discovery
           myBluetoothAdapter.cancelDiscovery();
       }
       else {
            BTArrayAdapter.clear();
            myBluetoothAdapter.startDiscovery();

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

I have searched google but did not find any solution.Any help will be great.

Upvotes: 0

Views: 119

Answers (1)

todd
todd

Reputation: 1286

First be sure that Bluetooth is enabled on the other devices. Then make the other devices discoverable. There should be an option in the bluetooth menu to make the device discoverable. The device will only be discoverable temporarily (usually about 2 minutes).

Upvotes: 1

Related Questions