How can we make bluetooth discoverable state off programmatically.
On first click(buton) I could able to make it discoverable and for second click on the same button Its not working
I mean if its in discoverable state I should make it off
Here is my code
bt_strength.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
// if (mBtAdapter.getScanMode()!= BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
if(!mBtAdapter.isDiscovering())
{
// if(bluetoothimg.getTag().toString().equalsIgnoreCase("off"))
Log.i(TAG, "BLUETOOTH STATUS ON");
bt_strength.setImageResource(R.drawable.bt);
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 3600);
startActivity(discoverableIntent);
}
else if(mBtAdapter.isDiscovering()){
bt_strength.setImageResource(R.drawable.bt_grey);
// Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
// discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 1);
// startActivity(discoverableIntent);
mBtAdapter.cancelDiscovery();
}
Any help is always appreciated, Thanks