I have made an app that uses bluetooth
In the oncreate()
method it enables bluetooth and sets the device visible for indefinite time
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(!adapter.isEnabled()) {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, REQUEST_ENABLE_BT);
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivity(discoverableIntent);
}
}
In onDestroy()
it disables the bluetooth
protected void onDestroy() {
// TODO Auto-generated method stub
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(adapter.isEnabled()) {
adapter.disable();
}
super.onDestroy();
}
But when i enable bluetooth again manually after exiting the app, It is automatically set to discoverable for indefinite time.
How do I set the bluetooth to Undiscoverable
before disabling it in the onDestroy()
function
Tested on Nexus 5 only