I need to know inside my app whether bluetooth is on or off. Or if bluetooth was turned on or off e.g. from the OS settings pulldown menu. I thought I could do this in the Activity's onResume()
. But it turns out that the activity is not paused when the Android OS's settings "pulldown menu" (the one that is accessed by pulling down with a finger from the top edge of the screen) is opened.
I need to update my UI when bluetooth becomes available or unavailable.
Can I register for a callback (e.g. a BroadcastReceiver
) or any other callback to let the system tell me when Bluetooth availability changes?
You can register the receiver with intent filter:
And this is the BroadcastReceiver:
Or if you want to add directly in the activity:
This is the intent-filter you need: