0

How can we have the bluetooth discoverable status on application start

I have an Image view for showing the status but its not showing the appropriate Image on start of applicaton

In oncreate() I have the following code

 mBtAdapter = BluetoothAdapter.getDefaultAdapter();


    if(mBtAdapter.isDiscovering()){
        bt_strength.setImageResource(R.drawable.bt);

    }
    else if (!mBtAdapter.isDiscovering()){
        bt_strength.setImageResource(R.drawable.bt_grey);
    }

Even this code also not working

      mBtAdapter = BluetoothAdapter.getDefaultAdapter();

     int status = mBtAdapter.getState();
    if(status == mBtAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE){
        bt_strength.setImageResource(R.drawable.bt);

    }
    else if (status == mBtAdapter.SCAN_MODE_NONE){
        bt_strength.setImageResource(R.drawable.bt_grey);
    }

How I can get around this problem? Any help is appreciated

Randroid
  • 3,688
  • 5
  • 30
  • 55

1 Answers1

3

use below code

   mBtAdapter = BluetoothAdapter.getDefaultAdapter();


    if(mBtAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
    {
        bt_strength.setImageResource(R.drawable.bt);

    }
    else 
    {
        bt_strength.setImageResource(R.drawable.bt_grey);
    }
Vivek Kumar Srivastava
  • 2,158
  • 1
  • 16
  • 23