0

I am able to list unpaired devices on scan discovery only if other devices are on their 'bluetooth setting screen'.If other devices are on their homepage then my application cannot find those devices. I have android 7 on my mobile phone and other devices have android 9 on them. Any help is appreciated.Thanks:)

public void startDiscovery()
{
    IntentFilter filter = new IntentFilter();
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    BA.startDiscovery();
    registerReceiver(mReceiver, filter);
    Toast.makeText(getApplicationContext(), "Discovery started", Toast.LENGTH_SHORT).show();
}

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.d("main","action found"+action);
            if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
                Toast.makeText(getApplicationContext(), "Discovery started", Toast.LENGTH_SHORT).show();
           } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
                Toast.makeText(getApplicationContext(), "Discovery finished", Toast.LENGTH_SHORT).show();
            } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                //Discovery has found a device. Get the BluetoothDevice
                // object and its info from the Intent.
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                String deviceName = device.getName();
                String deviceHardwareAddress = device.getAddress(); // MAC address
                Log.d("main","devicename"+deviceName);
                Log.d("main","deviceHardwareAddress"+deviceHardwareAddress);

        }
    };

    @Override
    protected void onDestroy() {
        Log.d("main","destroyed");
        super.onDestroy();
        BA.cancelDiscovery();
        // Don't forget to unregister the ACTION_FOUND receiver.
        unregisterReceiver(mReceiver);
    }
  • The way you've described things working is how they're supposed to work. What exactly is the problem? – Joseph Sible-Reinstate Monica Jun 19 '20 at 05:42
  • yes exactly.Its weird actually.If my other mobiles have bluetooth on but they are on home page or screen is off are not detected from my application which is doing scan discovery.If they are on bluetooth setting page then they get discovered very easily – prachi vadke Jun 19 '20 at 05:47
  • I want to say is application should be able to find devices with bluetooth ON,no matter on what screen the other devices are.Which is not happening now. – prachi vadke Jun 19 '20 at 05:49

1 Answers1

0

Its not being discovered because its hidden according to the bt protocol however see https://stackoverflow.com/a/36984988/8461344

Code Demon
  • 1,256
  • 1
  • 9
  • 15